CVR-Lib last update 20 Sep 2009

cvr::internal::switch_t< X, CASE > Struct Template Reference

A compile time switch statement. More...

#include <cvrMetaProgrammingTools.h>

List of all members.


Detailed Description

template<int X, class CASE>
struct cvr::internal::switch_t< X, CASE >

A compile time switch statement.

It is recommended to use enum values or static const int members for specifying X as well as the case parameters.

The following examples clarify the syntax. They all use the following setup, that defines a type foo<X>::type that is dependent on the value of X:

 enum VAL{One, Two, Three};
 template <VAL X>
 struct foo {
   typedef typename internal::switch_t<X, .....>::type type;
 }

The most simple case is just a default type:

 typedef typename internal::switch_t<X,
   internal::default_t<int> >::type type;

Just one case could have been done using if_t as well, but like this it is more easily extended. Here, if X == One then type is float otherwise type is int.

 typedef typename internal::switch_t<X,
   internal::case_t<One, float,
   internal::default_t<int> > >::type type;

Finally, and recommended, include all possible values as cases in the enum and supply a default that will lead to a notification of some sort. Note that it is considered bad style not to provide a default.

 typedef typename internal::switch_t<X,
   internal::case_t<One, int,
   internal::case_t<Two, float,
   internal::case_t<Three, std::complex<float>,
   internal::default_t<void> > > > >::type type;

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

Generated on Sun Sep 20 22:09:12 2009 for CVR-Lib by Doxygen 1.5.8