dune-common 2.1.1
Public Types | Public Member Functions | Static Public Attributes
Dune::Int2Type< N > Struct Template Reference

Map an integer value to a type. More...

#include <dune/common/misc.hh>

Inheritance diagram for Dune::Int2Type< N >:
Inheritance graph

List of all members.

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.

Detailed Description

template<int N>
struct Dune::Int2Type< N >

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.

Deprecated:
This class is deprecated as of Dune 2.0+1 and will be removed in Dune 2.0+2. Please use integral_constant from <dune/common/typetraits.hh> instead.

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.


Member Typedef Documentation

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


Constructor & Destructor Documentation

template<int N>
Dune::Int2Type< N >::Int2Type ( ) [inline]

Default constructor.

Deprecated:
This member is deprecated to make warnings more likely since deprecation of the class itself is unreliable.
Deprecated:

Member Function Documentation

Dune::integral_constant< int , v >::operator value_type ( ) [inline, inherited]

conversion to value_type/T

References Dune::integral_constant< T, v >::value.


Member Data Documentation

template<int N>
const int Dune::Int2Type< N >::value = N [static]

Export template parameter.

Deprecated:
This member is deprecated to make warnings more likely since deprecation of the class itself ins unreliable.
Deprecated:

Reimplemented from Dune::integral_constant< int, N >.


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