All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | List of all members
blaze::EnableIfTrue< Condition, T > Struct Template Reference

Substitution Failure Is Not An Error (SFINAE) class.The EnableIfTrue class template is an auxiliary tool for an intentional application of the Substitution Failure Is Not An Error (SFINAE) principle. It allows a function template or a class template specialization to include or exclude itself from a set of matching functions or specializations based on properties of its template arguments. For instance, it can be used to restrict the selection of a function template to specific data types. The following example illustrates this in more detail. More...

#include <EnableIf.h>

Public Types

typedef T Type
 The instantiated type.
 

Detailed Description

template<bool Condition, typename T = void>
struct blaze::EnableIfTrue< Condition, T >

Substitution Failure Is Not An Error (SFINAE) class.

The EnableIfTrue class template is an auxiliary tool for an intentional application of the Substitution Failure Is Not An Error (SFINAE) principle. It allows a function template or a class template specialization to include or exclude itself from a set of matching functions or specializations based on properties of its template arguments. For instance, it can be used to restrict the selection of a function template to specific data types. The following example illustrates this in more detail.

template< typename Type >
void process( Type t ) { ... }

Due to the general formulation of this function, it will always be a possible candidate for every possible argument. However, with the EnableIfTrue class it is for example possible to restrict the valid argument types to built-in, numeric data types.

template< typename Type >
typename EnableIfTrue< IsNumeric<Type>::value >::Type process( Type t ) { ... }

In case the given data type is not a built-in, numeric data type, the access to the nested type defintion Type of the EnableIfTrue template will fail. However, due to the SFINAE principle, this will only result in a compilation error in case the compiler cannot find another valid function.
Note that in this application of the EnableIfTrue template the default for the nested type definition Type is used, which corresponds to void. Via the second template argument it is possible to explicitly specify the type of Type:

// Explicity specifying the default
typename EnableIfTrue< IsNumeric<Type>::value, void >::Type
// In case the given data type is a boolean data type, the nested type definition
// 'Type' is set to float
typename EnableIfTrue< IsBoolean<Type>::value, float >::Type

For more information on the EnableIfTrue/EnableIf functionality, see the Boost library documentation of the enable_if family at:

http://www.boost.org/doc/libs/1_40_0/libs/utility/enable_if.html.


The documentation for this struct was generated from the following file: