Public Types | List of all members
blaze::DisableIfTrue< Condition, T > Struct Template Reference

Substitution Failure Is Not An Error (SFINAE) class.The DisableIfTrue 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 <DisableIf.h>

Public Types

typedef T Type
 The instantiated type.
 

Detailed Description

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

Substitution Failure Is Not An Error (SFINAE) class.

The DisableIfTrue 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 DisableIfTrue class it is for example possible to prohibit built-in, numeric data types as argument types:

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

In case the given data type is a built-in, numeric data type, the access to the nested type definition Type of the DisableIfTrue class 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 DisableIfTrue 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 DisableIfTrue< IsNumeric<Type>::value, void >::Type
// In case the given data type is not a boolean data type, the nested type definition
// 'Type' is set to float
typename DisableIfTrue< IsBoolean<Type>::value, float >::Type

For more information on the DisableIfTrue/DisableIf 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: