All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Macros | Typedefs | Functions
TemplateUtils.h File Reference
#include <type_traits>

Go to the source code of this file.

Namespaces

 Aux
 

Macros

#define AUX_REQUIRE(what,...)   class what = typename ::std::enable_if<__VA_ARGS__>::type
 The macro makes the use of std::enable_if much easier by removing all the boilerplate. More...
 
#define AUX_DUMMY_ARGUMENT   class = void
 If two templates only differ in the default-values of their template-arguments C++ considers this to be a compilation-error. More...
 

Typedefs

template<typename T >
using Aux::decay_t = typename std::decay< T >::type
 This is a backport of C++14 std::decay_t. More...
 
template<bool B>
using Aux::boolToType = std::integral_constant< bool, B >
 Returns the corresponding std::integral_constant<bool, B> to a boolean value B. More...
 

Functions

template<typename T1 , typename T2 >
constexpr bool Aux::isSame ()
 This is just a wrapper around std::is_same in order to provide a nicer interface. More...
 
template<typename Base , typename Derived >
constexpr bool Aux::isBaseOrSame ()
 Checks whether Derived is either a type that derives from Base or is identical to Base. More...
 

Macro Definition Documentation

#define AUX_DUMMY_ARGUMENT   class = void

If two templates only differ in the default-values of their template-arguments C++ considers this to be a compilation-error.

A simple way to prevent this is to add further defaulted template-arguments, which is what this macro provides in a semantic way.

Example:

template<typename T, AUX_REQUIRE(isInteger, [...])> void fun(T) {...}

template<typename T, AUX_REQUIRE(isFloat, [...]), AUX_DUMMY_ARGUMENT> void fun(T) {...}

Note however that it may often be a cleaner solution to use compile-time dispatching instead of hacks that envolve enable-if.

#define AUX_REQUIRE (   what,
  ... 
)    class what = typename ::std::enable_if<__VA_ARGS__>::type

The macro makes the use of std::enable_if much easier by removing all the boilerplate.

The 'what' argument must be a valid identifier that describes, what is required. Example: you want to require that T is an integer, than what should be something like T_is_integer

The second argument must be a constant boolean expression. In order to allow templates that would otherwise confuse the preprocessor, this is passed as variadic argument (this is however an implementation detail and you should never actually pass more than one argument.