Group Switch Metafunction Types
Tags for the metafunction Switch and the metafunction itself.
Tags for the metafunction Switch and the metafunction itself.
Grouped Tags Overview
-
struct NilCase {};
Tag for terminating the case in Switch statement.
Grouped Metafunction Overview
-
template <int TAG, typename TResult, typename TNext> struct Case;
Tag for one case. -
Switch<TAG, TCase>::Type
Switch statement for metaprogramming.
Detailed Description
Example
The following shows a complete example of using the Switch statement.
int switchTest(Nothing const &)
{
return -1;
}
int switchTest(False const &)
{
return 0;
}
int switchTest(True const &)
{
return 1;
}
int switchTest(NilCase const &)
{
return 2;
}
template <int X>
struct SwitchTest
{
typedef typename Switch<
X,
Case<-1, Nothing,
Case<0, False,
Case<1, True
> > > >::Type Type;
};
int main()
{
typedef SwitchTest<-1>::Type T1;
typedef SwitchTest<0>::Type T2;
typedef SwitchTest<1>::Type T3;
typedef SwitchTest<2>::Type T4;
std::cout << switchTest(T1()) << "\n" // => "-1"
<< switchTest(T2()) << "\n" // => "0"
<< switchTest(T3()) << "\n" // => "1"
<< switchTest(T4()) << "\n"; // => "2"
return 0;
}
Snippet from: demos/dox/basic/metaprogramming_switch.cpp