FreePOOMA
2.4.1
|
Helper class: WrappedInt<int> More...
#include <WrappedInt.h>
Public Types | |
enum | { val = Integer } |
Helper class: WrappedInt<int>
A tag class templated on an integer. This class is intended to be used to let you specialize a function on a compile time number.
For example, if you have an object of type T which you want to pass to a subroutine foo, but you want to specialize that subroutine based on the enum 'bar' defined in T, you could say:
template<class T> void foo(const T& t) { foo(t,WrappedInt<T::bar>()) }
You can then specialize foo(T,WrappedInt<x>) for different values of x.
With functor classes you can do this in a slightly slicker manner. Define the general functor class like so:
template< class T, class Switch = WrappedInt<T::bar> > struct Foo { static void foo()(const T& t); }
Then you can specialize foo for different values of Switch. That is you write things like Foo<T,WrappedInt<1>>::foo(const T&) to specialize it for T::bar==1.
With this construction you don't have two function calls and the WrappedInt is never constructed or passed. Since it relies on Foo being templated though, you can't use it nested in another class.