by gnuyuva <gnuyuva@[EMAIL PROTECTED]
>
May 9, 2008 at 05:07 AM
On May 9, 4:29 pm, Christof Warlich <cwarl...@[EMAIL PROTECTED]
>
wrote:
> Hi all,
>
> As the definition of the index - value pairs are supposed to become part
of the API, does anyone
> have an idea how this could be beautified?
>
> Thanks,
>
> Christof
>
> #include <iostream>
> using namespace std;
>
> // definition of the index - value pairs
> template<unsigned int index> struct Value {};
> template<> struct Value<0> {static const unsigned int value = 1;};
> template<> struct Value<1> {static const unsigned int value = 10;};
> template<> struct Value<2> {static const unsigned int value = 100;};
> template<> struct Value<3> {static const unsigned int value = 1000;};
> template<> struct Value<4> {static const unsigned int value = 10000;};
>
use recursive templates.
enum { multiplier = 10 };
template <unsigned int index> struct value
{
static const long long int this_value = value< index-1>::this_value
* multiplier;
}
template <> struct value<0> { enum { this_value = 1 }; } //
termination condition.
since the depth of template recursion is limited (say 17 is the upper
limit)
template <> struct value<17> {}; // let there be compilation error.