Skip to content

Commit da87408

Browse files
authored
Merge pull request #5788 from ab9rf/enum_field_flexicast
improve `enum_field` with more flexible casting
2 parents 7e7886e + ab5b437 commit da87408

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Template for new versions:
6565
## Documentation
6666

6767
## API
68+
- add flexible casting to ``enum_field`` to enable explicit casting to more types
6869

6970
## Lua
7071

library/include/DataDefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ namespace df
632632
enum_field<EnumType,IntType> &operator=(EnumType ev) {
633633
value = IntType(ev); return *this;
634634
}
635+
explicit operator IntType () const { return IntType(value); }
636+
template <typename T>
637+
explicit operator T () const { return static_cast<T>(IntType(value)); }
638+
635639
};
636640

637641
template<class ET, class IT>

0 commit comments

Comments
 (0)