TypeSafe< T, Derived > Class Template Reference

CPP API: mio::TypeSafe< T, Derived > Class Template Reference

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

get () const
 
 operator T () const
 conversion to 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

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. class Foo : public Type<int, Foo>() {}; class Bar : public Type<int, Bar>() {}; void work(Foo f, Bar b); instead of void work(int f, int b);

Template Parameters
Ttype of the underlying value
DerivedConcrete type derived from this type for CRTP.

Member Typedef Documentation

◆ ValueType

template<class T , class Derived >
using mio::TypeSafe< T, Derived >::ValueType = T

Constructor & Destructor Documentation

◆ TypeSafe() [1/2]

template<class T , class Derived >
mio::TypeSafe< T, Derived >::TypeSafe ( )
default

default constructor.

◆ TypeSafe() [2/2]

template<class T , class Derived >
mio::TypeSafe< T, Derived >::TypeSafe ( t)
inlineexplicit

value constructor.

Member Function Documentation

◆ deserialize()

template<class T , class Derived >
template<class IOContext >
static IOResult<Derived> mio::TypeSafe< T, Derived >::deserialize ( IOContext &  io)
inlinestatic

deserialize an object of this class.

See also
mio::deserialize

◆ get()

template<class T , class Derived >
T mio::TypeSafe< T, Derived >::get ( ) const
inline

◆ operator T()

template<class T , class Derived >
mio::TypeSafe< T, Derived >::operator T ( ) const
inlineexplicit

conversion to underlying type.

◆ serialize()

template<class T , class Derived >
template<class IOContext >
void mio::TypeSafe< T, Derived >::serialize ( IOContext &  io) const
inline

serialize this.

See also
mio::serialize

Friends And Related Function Documentation

◆ operator!=

template<class T , class Derived >
bool operator!= ( const Derived &  a,
const Derived &  b 
)
friend

◆ operator<<

template<class T , class Derived >
std::ostream& operator<< ( std::ostream &  os,
const Derived &  ts 
)
friend

stream operators.

◆ operator==

template<class T , class Derived >
bool operator== ( const Derived &  a,
const Derived &  b 
)
friend

equality operators.

Member Data Documentation

◆ m_t

template<class T , class Derived >
T mio::TypeSafe< T, Derived >::m_t
private