Evo C++ Library v0.5.1
Classes | Macros | Typedefs | Functions
EvoMeta

Evo metaprogramming types and helpers. More...

Classes

struct  AddConst< T >
 Add const to type. More...
 
struct  EvoContainer< T >
 Trait to identify Evo container types. More...
 
struct  IsArray< T >
 Check if type is an array. More...
 
struct  IsBool< T >
 Check if type is a boolean (true/false) type. More...
 
struct  IsByteCopyType< T >
 Check if type is a ByteCopy type. More...
 
struct  IsConst< T >
 Check if type is const. More...
 
class  IsConvertible< T, U >
 Check if type T is convertible to type U. More...
 
class  IsEvoContainer< T >
 Check if type is an EvoContainer. More...
 
struct  IsFloat< T >
 Check if type is a floating point type. More...
 
struct  IsInt< T >
 Check if type is an integer (whole number) type. More...
 
struct  IsNormalType< T >
 Check if type is a normal type (not POD and not ByteCopy type). More...
 
class  IsNullable< T >
 Check if type is nullable. More...
 
struct  IsPodType< T >
 Check if type is a Plan Old Data type. More...
 
struct  IsPointer< T >
 Check if type is a pointer. More...
 
struct  IsReference< T >
 Check if type is a reference. More...
 
struct  IsSame< T1, T2 >
 Check if types are exactly the same. More...
 
struct  IsSigned< T >
 Check if integer type is unsigned. More...
 
struct  RemoveConst< T >
 Remove const from type. More...
 
struct  RemoveConstVol< T >
 Remove const & volatile from type. More...
 
struct  RemoveExtents< T >
 Remove extents (pointer and array parts) from type. More...
 
struct  RemoveExtentsConstVol< T >
 Remove extents (pointer and array parts) and then const & volatile from type. More...
 
struct  RemoveVolatile< T >
 Remove volatile from type. More...
 
struct  StaticBool< val >
 Static bool value. More...
 
struct  StaticIf< b, T, F >
 Static conditional type. More...
 
struct  ToSigned< T >
 Translate integer type to signed. More...
 
struct  ToUnsigned< T >
 Translate integer type to unsigned. More...
 
struct  TypeId
 Type ID info (POD, ByteCopy, Normal). More...
 

Macros

#define EVO_BCTYPE(Type)   namespace evo { template<> struct ByteCopyType<Type> : public StaticBoolT { }; }
 Identify the given type as a Byte-Copy type. More...
 
#define EVO_CONTAINER(Type)   EVO_TRAIT_NSET(evo,EvoContainer,Type)
 Identify given type as an EvoContainer. More...
 
#define EVO_CONTAINER_TYPE   typedef void EvoContainerType
 Identify current class/struct as an EvoContainer. More...
 
#define EVO_CREATE_HAS_METHOD(TypeName, ReturnType, Func, ...)
 Create template to check if type has a member function matching given signature. More...
 
#define EVO_CREATE_HAS_METHOD_CONST(TypeName, ReturnType, Func, ...)
 Create template to check if type has a const member function matching given signature. More...
 
#define EVO_CREATE_HAS_VAR(TypeName, VarType, VarName)
 Create template to check if type has a member variable matching given signature. More...
 
#define EVO_PODTYPE(Type)   namespace evo { template<> struct PodType<Type> : public StaticBoolT { }; }
 Identify given type as a Plain Old Data Type. More...
 
#define EVO_STATIC_JOIN(A, B)   IMPL_EVO_STATIC_JOIN1(A,B)
 Join (concatenate) compile-time symbols after resolving macros. More...
 
#define EVO_TRAIT_CREATE(Name)   template<class T> struct Name : StaticBoolF { };
 Helper for creating a boolean trait type. More...
 
#define EVO_TRAIT_NSET(Namespace, Name, Type)   namespace Namespace { template<> struct Name< Type > : public StaticBoolT { }; }
 Helper for setting a boolean trait for given type. More...
 
#define EVO_TRAIT_SET(Name, Type)   template<> struct Name< Type > : public StaticBoolT { };
 Helper for setting a boolean trait for given type. More...
 
#define EVO_TYPE_SELECT(T, Pod, Bc, Normal)   typename StaticIf<IsPodType<T>::value,Pod,typename StaticIf<IsByteCopyType<T>::value,Bc,Normal>::Type>::Type
 Select a type depending on whether Type is POD, ByteCopy, or Normal type. More...
 
#define STATIC_ASSERT(EXP, TOKEN)   static_assert(EXP,#TOKEN)
 Assert compile-time expression is true or trigger compiler error. More...
 
#define STATIC_ASSERT_FUNC_UNUSED   =delete;
 Assert a function is unused at compile-time. More...
 
#define STATIC_ASSERT_FUNC_UNUSED_RET(RET)   =delete;
 Assert a function is unused at compile-time (with return value). More...
 

Typedefs

typedef StaticBool< false > StaticBoolF
 Static bool value (false). More...
 
typedef StaticBool< true > StaticBoolT
 Static bool value (true). More...
 

Functions

template<class T >
bool is_null (const T &val)
 Check whether object or value is null. More...
 

Detailed Description

Evo metaprogramming types and helpers.

Macro Definition Documentation

◆ EVO_BCTYPE

#define EVO_BCTYPE (   Type)    namespace evo { template<> struct ByteCopyType<Type> : public StaticBoolT { }; }

Identify the given type as a Byte-Copy type.

  • Byte-Copy types may be directly byte-copied for improved performance.
  • Containers take advantage of these rules with performance optimizations.
  • This can only be used in global scope.
Parameters
TypeType name to set as ByteCopy type.
See also
EVO_PODTYPE()
Example
struct Foo { };

◆ EVO_CONTAINER

#define EVO_CONTAINER (   Type)    EVO_TRAIT_NSET(evo,EvoContainer,Type)

Identify given type as an EvoContainer.

  • The type must meet the requirements of EvoContainer, otherwise results are undefined
  • See Primitives & Containers
  • Must use at global scope (no namespace) since this modifies evo namespace
Parameters
TypeType to identify as EvoContainer

◆ EVO_CONTAINER_TYPE

#define EVO_CONTAINER_TYPE   typedef void EvoContainerType

Identify current class/struct as an EvoContainer.

  • The type must meet the requirements of EvoContainer, otherwise results are undefined
  • Use in class/struct scope, anywhere a typedef is valid
Example
#include <evo/type.h>
class Foo {
// ...
};
class Bar { };
void main() {
bool b1 = IsEvoContainer<Foo>::value; // true
bool b2 = IsEvoContainer<Bar>::value; // false
}

◆ EVO_CREATE_HAS_METHOD

#define EVO_CREATE_HAS_METHOD (   TypeName,
  ReturnType,
  Func,
  ... 
)
Value:
template<class T> class TypeName { \
template<class U, ReturnType (U::*)(__VA_ARGS__)> struct SFINAE { }; \
template<class U> static char Test(SFINAE<U, &U::Func>*); \
template<class U> static long Test(...); \
public: \
static const bool value = (sizeof(Test<T>(0)) == sizeof(char)); \
}

Create template to check if type has a member function matching given signature.

  • This defines a template class that can detect the given member function signature
  • To check for const member function see: EVO_CREATE_HAS_METHOD_CONST()
Parameters
TypeNameTemplate type name to create
ReturnTypeMember function return type
FuncMember function name
...Member function parameter types (0 or more)
Example
struct Class1 {
void foo();
};
struct Class2 {
void foo(int);
};
struct Class3 {
int foo(int);
};
EVO_CREATE_HAS_METHOD(HasFoo, void, foo);
EVO_CREATE_HAS_METHOD(HasFooInt, void, foo, int);
EVO_CREATE_HAS_METHOD(HasIntFooInt, int, foo, int);
void main() {
bool b1 = HasFoo<Class1>::value; // true
bool b2 = HasFooInt<Class2>::value; // true
bool b3 = HasIntFooInt<Class3>::value; // true
bool b4 = HasIntFooInt<Class1>::value; // false
}

◆ EVO_CREATE_HAS_METHOD_CONST

#define EVO_CREATE_HAS_METHOD_CONST (   TypeName,
  ReturnType,
  Func,
  ... 
)
Value:
template<class T> class TypeName { \
template<typename U, ReturnType (U::*)(__VA_ARGS__) const> struct SFINAE { }; \
template<typename U> static char Test(SFINAE<U, &U::Func>*); \
template<typename U> static long Test(...); \
public: \
static const bool value = (sizeof(Test<T>(0)) == sizeof(char)); \
}

Create template to check if type has a const member function matching given signature.

  • This defines a template class that can detect the given member function signature
  • To check for non-const member function see: EVO_CREATE_HAS_METHOD()
Parameters
TypeNameTemplate type name to create
ReturnTypeMember function return type
FuncMember function name
...Member function parameter types (0 or more)
Example
struct Class1 {
void foo() const;
};
struct Class2 {
void foo(int) const;
};
struct Class3 {
int foo(int) const;
};
EVO_CREATE_HAS_METHOD_CONST(HasFoo, void, foo);
EVO_CREATE_HAS_METHOD_CONST(HasFooInt, void, foo, int);
EVO_CREATE_HAS_METHOD_CONST(HasIntFooInt, int, foo, int);
void main() {
bool b1 = HasFoo<Class1>::value; // true
bool b2 = HasFooInt<Class2>::value; // true
bool b3 = HasIntFooInt<Class3>::value; // true
bool b4 = HasIntFooInt<Class1>::value; // false
}

◆ EVO_CREATE_HAS_VAR

#define EVO_CREATE_HAS_VAR (   TypeName,
  VarType,
  VarName 
)
Value:
template<class T> class TypeName { \
template<class U, VarType U::*> struct SFINAE { }; \
template<class U> static char Test(SFINAE<U, &U::VarName>*); \
template<class U> static long Test(...); \
public: \
static const bool value = (sizeof(Test<T>(0)) == sizeof(char)); \
}

Create template to check if type has a member variable matching given signature.

  • This defines a template class that can detect the given member variable signature
Parameters
TypeNameTemplate type name to create
VarTypeMember function return type
VarNameMember function name
Example
struct Class1 {
int foo;
};
struct Class2 {
const int foo;
};
struct Class3 {
long foo;
};
EVO_CREATE_HAS_VAR(HasIntFoo, int, foo);
EVO_CREATE_HAS_VAR(HasCIntFoo, const int, foo);
EVO_CREATE_HAS_VAR(HasLongFoo, long, foo);
void main() {
bool b1 = HasIntFoo<Class1>::value; // true
bool b2 = HasCIntFoo<Class2>::value; // true
bool b3 = HasLongFoo<Class3>::value; // true
bool b4 = HasLongFoo<Class1>::value; // false
}

◆ EVO_PODTYPE

#define EVO_PODTYPE (   Type)    namespace evo { template<> struct PodType<Type> : public StaticBoolT { }; }

Identify given type as a Plain Old Data Type.

  • POD types do not use any constructors, assignment operators, or destructor; and may be directly byte-copied
  • All built-in types and pointer types are considered POD types – it's unlikely you'll need to use this directly
  • Containers take advantage of these rules with performance optimizations
  • This can only be used in global scope
Parameters
TypeType name to set as POD type.
See also
EVO_BCTYPE()
Example
struct Foo { };

◆ EVO_STATIC_JOIN

#define EVO_STATIC_JOIN (   A,
 
)    IMPL_EVO_STATIC_JOIN1(A,B)

Join (concatenate) compile-time symbols after resolving macros.

  • This resolves A and B if they're macros, then joins (concatenates) them together as one symbol
Parameters
AFirst symbol/macro to join
BSecond symbol/macro to join
Returns
Joined symbol

◆ EVO_TRAIT_CREATE

#define EVO_TRAIT_CREATE (   Name)    template<class T> struct Name : StaticBoolF { };

Helper for creating a boolean trait type.

  • The trait value will be true for types explicitly set, otherwise defaults to false
  • Use EVO_TRAIT_SET() or EVO_TRAIT_NSET() to set trait values
  • Use only at namespace scope, not struct/class scope (this uses template specialization)
Parameters
NameName for trait type

◆ EVO_TRAIT_NSET

#define EVO_TRAIT_NSET (   Namespace,
  Name,
  Type 
)    namespace Namespace { template<> struct Name< Type > : public StaticBoolT { }; }

Helper for setting a boolean trait for given type.

  • This sets the trait value to true for given type
  • Must create trait first with EVO_TRAIT_CREATE()
  • Use only at global scope (not inside a namespace)
Parameters
NamespaceNamespace for trait
NameName for trait type – same name created with EVO_TRAIT_CREATE()
TypeType to set trait for
Example
namespace foo {
EVO_TRAIT_CREATE(IsSignedInt);
}
EVO_TRAIT_NSET(foo,IsSignedInt,int);
EVO_TRAIT_NSET(foo,IsSignedInt,long);
void main() {
bool b1 = foo::IsSignedInt<int>::value; // true
bool b2 = foo::IsSignedInt<long>::value; // true
bool b3 = foo::IsSignedInt<char>::value; // false
}

◆ EVO_TRAIT_SET

#define EVO_TRAIT_SET (   Name,
  Type 
)    template<> struct Name< Type > : public StaticBoolT { };

Helper for setting a boolean trait for given type.

  • This sets the trait value to true for given type
  • Must create trait first with EVO_TRAIT_CREATE()
  • Use only in same namespace as created
Parameters
NameName for trait type – same name created with EVO_TRAIT_CREATE()
TypeType to set trait for
Example
EVO_TRAIT_CREATE(IsSignedInt);
EVO_TRAIT_SET(IsSignedInt,int);
EVO_TRAIT_SET(IsSignedInt,long);
void main() {
bool b1 = IsSignedInt<int>::value; // true
bool b2 = IsSignedInt<long>::value; // true
bool b3 = IsSignedInt<char>::value; // false
}

◆ EVO_TYPE_SELECT

#define EVO_TYPE_SELECT (   T,
  Pod,
  Bc,
  Normal 
)    typename StaticIf<IsPodType<T>::value,Pod,typename StaticIf<IsByteCopyType<T>::value,Bc,Normal>::Type>::Type

Select a type depending on whether Type is POD, ByteCopy, or Normal type.

  • See: IsPodType(), IsByteCopyType(), IsNormalType()
Parameters
TType to check
PodType to use if POD type
BcType to use if ByteCopy type
NormalType to use if Normal type
Returns
Selected type (Pod, Bc, or Normal)

◆ STATIC_ASSERT

#define STATIC_ASSERT (   EXP,
  TOKEN 
)    static_assert(EXP,#TOKEN)

Assert compile-time expression is true or trigger compiler error.

  • This uses some template magic to cause a custom compiler error if given expression is false
  • With C++11 this just calls static_assert()
Parameters
EXPCompile-time expression to evaluate.
TOKENError message token in the form of a type name that explains the error (not a string).
Example
STATIC_ASSERT(true, Assert_failed__Test_message); // ok, no-op
STATIC_ASSERT(false, Assert_failed__Test_message); // compiler error: assert fails

◆ STATIC_ASSERT_FUNC_UNUSED

#define STATIC_ASSERT_FUNC_UNUSED   =delete;

Assert a function is unused at compile-time.

  • This marks a function so that compiling will fail if the function is used (called)
  • This replaces the function implementation – see example below
  • This should only be used with function defined in a class (or struct) or as inline
  • With C++11 this marks the function as deleted
  • Without C++11, some compilers (clang) won't show an error until linking phase (undefined function)
Example
struct Foo {
void foo()
};
int foo()

◆ STATIC_ASSERT_FUNC_UNUSED_RET

#define STATIC_ASSERT_FUNC_UNUSED_RET (   RET)    =delete;

Assert a function is unused at compile-time (with return value).

  • Same as STATIC_ASSERT_FUNC_UNUSED, but includes a return value to suppress warnings on missing return value
struct Foo {
int bar()
};
int bar()
Parameters
RETReturn value for function

Typedef Documentation

◆ StaticBoolF

typedef StaticBool<false> StaticBoolF

Static bool value (false).

◆ StaticBoolT

typedef StaticBool<true> StaticBoolT

Static bool value (true).

Function Documentation

◆ is_null()

bool evo::is_null ( const T &  val)
inline

Check whether object or value is null.

Template Parameters
TType to check, inferred from argument
Parameters
valObject or value to check if null
Returns
Whether object or value is null