dune-common 2.1.1
|
Map an integer value to a type. More...
#include <dune/common/misc.hh>
Public Types | |
typedef int | value_type |
type of value | |
typedef integral_constant< int, v > | type |
type of this class itself | |
Public Member Functions | |
Int2Type () | |
Default constructor. | |
operator value_type () | |
conversion to value_type/T | |
Static Public Attributes | |
static const int | value = N |
Export template parameter. |
Map an integer value to a type.
This comes in handy if one tries to emulate member function specialization. The idea how to do it is presented in "Modern C++ Design" by Alexandrescu.
Migration path: The most common use of Int2Type is a replacement of the disallowed partial specialization of functions: to select a particular function from an overloaded set, give it a dummy argument of type Int2Type.
template<int N> void foo(const Int2Type<N>&, ...); void foo(const Int2Type<0>&, ...); // "specialization" for N=0
Since Int2Type<...> is now derived from integral_constant<int,...>, the above can safely be replaced by
template<int N> void foo(const integral_constant<int,N>&, ...); void foo(const integral_constant<int,0>&, ...); // "specialization" for N=0
Compatibility overloads with Int2Type instead of integral_constant<int,...> are needed. However, the call to such functions cannot be migrated that easily:
// works for declaration foo(const Int2Type<dim>&, ...) // as well as foo(const integral_constant<int,dim>&, ...) foo(Int2Type<dim>(), args); // works for declaration foo(const integral_constant<int,dim>&, ...) only foo(integral_constant<int,dim>(), args);
So, before a call is migrated, the declaration of all functions that are possibly called have to be migrated.
typedef integral_constant<int ,v> Dune::integral_constant< int , v >::type [inherited] |
type of this class itself
typedef int Dune::integral_constant< int , v >::value_type [inherited] |
type of value
Dune::Int2Type< N >::Int2Type | ( | ) | [inline] |
Default constructor.
Dune::integral_constant< int , v >::operator value_type | ( | ) | [inline, inherited] |
conversion to value_type/T
References Dune::integral_constant< T, v >::value.
const int Dune::Int2Type< N >::value = N [static] |
Export template parameter.
Reimplemented from Dune::integral_constant< int, N >.