TypeSafe< T, Derived > Class Template Reference
|
CPP API
|
Typesafe wrapper around any type to make function arguments, tuple elements, etc. More...
#include <type_safe.h>
Public Types | |
| using | ValueType = T |
Public Member Functions | |
| T | get () const |
| Returns the underlying value. More... | |
| operator T () const | |
| Explicit conversion to the underlying type. More... | |
| template<class IOContext > | |
| void | serialize (IOContext &io) const |
| serialize this. More... | |
| TypeSafe ()=default | |
| default constructor. More... | |
| TypeSafe (T t) | |
| value constructor. More... | |
Static Public Member Functions | |
| template<class IOContext > | |
| static IOResult< Derived > | deserialize (IOContext &io) |
| deserialize an object of this class. More... | |
Private Attributes | |
| T | m_t |
Friends | |
| bool | operator!= (const Derived &a, const Derived &b) |
| std::ostream & | operator<< (std::ostream &os, const Derived &ts) |
| stream operators. More... | |
| bool | operator== (const Derived &a, const Derived &b) |
| equality operators. More... | |
Detailed Description
template<class T, class Derived>
class mio::TypeSafe< T, Derived >
Typesafe wrapper around any type to make function arguments, tuple elements, etc.
easily distinguishable. e.g.
instead of
The underlying value can be accessed via the get() member function or via an explicit cast:
Additional arithmetic and comparison operators can be mixed in by deriving from the operator helper classes OperatorAdditionSubtraction, OperatorScalarMultiplicationDivision, OperatorComparison, and OperatorIncrementDecrement. Alternatively, use the DECL_TYPESAFE macro for a simple one-line declaration.
- Template Parameters
-
T Type of the underlying value. Derived Concrete type derived from this class (CRTP).
Member Typedef Documentation
◆ ValueType
| using mio::TypeSafe< T, Derived >::ValueType = T |
Constructor & Destructor Documentation
◆ TypeSafe() [1/2]
|
default |
default constructor.
◆ TypeSafe() [2/2]
|
inlineexplicit |
value constructor.
Member Function Documentation
◆ deserialize()
|
inlinestatic |
deserialize an object of this class.
- See also
- mio::deserialize
◆ get()
|
inline |
Returns the underlying value.
This is the preferred way to access the raw value of a TypeSafe wrapper.
◆ operator T()
|
inlineexplicit |
Explicit conversion to the underlying type.
Prefer get() for clarity.
◆ serialize()
|
inline |
serialize this.
- See also
- mio::serialize
Friends And Related Function Documentation
◆ operator!=
|
friend |
◆ operator<<
|
friend |
stream operators.
◆ operator==
|
friend |
equality operators.
Member Data Documentation
◆ m_t
|
private |
Generated by