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(seqan::Nothing const &) { return -1; } int switchTest(seqan::False const &) { return 0; } int switchTest(seqan::True const &) { return 1; } int switchTest(seqan::NilCase const &) { return 2; } template <int X> struct SwitchTest { typedef typename seqan::Switch< X, seqan::Case<-1, seqan::Nothing, seqan::Case<0, seqan::False, seqan::Case<1, seqan::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/basic/metaprogramming_switch.cpp