Loops, Metaloops, & C++
By Roshan Naik, August 01, 2004
Metaloops are implemented in C++ using recursive template instantiation. Roshan examines ideas around encapsulating metaloops and considers their usefulness.
August, 2004: Loops, Metaloops, & C++
Listing 6
// Compile-time selection
// primary template chooses T when b is true
template <bool b , typename T , typename F>
struct If_else
{
typedef T result;
};
// specialization choses F when b is false
template <typename T , typename F>
struct If_else <false , T , F>
{
typedef F result;
};