Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: compile tim...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 45824 of 46738
Post > Topic >>

Re: compile time value -> index calculation

by gnuyuva <gnuyuva@[EMAIL PROTECTED] > May 10, 2008 at 01:33 AM

On May 9, 6:06 pm, Christof Warlich <cwarl...@[EMAIL PROTECTED]
>
wrote:
> gnuyuva schrieb:
>
>
>
> > 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.
>
> Thanks, but this is not what I was looking for.
>
> I should have been more precise: I want to be able to define any
arbitrary
> indexed sequence of constant values, as long as the values are
increasing.
> Thus, this could be another example:
>
> // definition of the index - value pairs
> template<unsigned int index> struct Value {};
> template<> struct Value<0> {static const unsigned int value = 27;};
> template<> struct Value<1> {static const unsigned int value = 33;};
> template<> struct Value<2> {static const unsigned int value = 815;};
> template<> struct Value<3> {static const unsigned int value = 4711;};
>
> Again, writing this with an array would be quite convenient:
>
> const unsigned int a[] = {27, 33, 815, 4711};
>
> but the array elements are obviously not allowed to be used in a
constant
> expression.
>
> Sorry for making this not clear enough.

Well, in that case you don't have any other go but to write them
manually. Maybe you can reduce your typing effort by writing a macro.
or wait till c++0x for 'constexpr' ;-)
 




 4 Posts in Topic:
compile time value -> index calculation
Christof Warlich <cwar  2008-05-09 13:29:50 
Re: compile time value -> index calculation
gnuyuva <gnuyuva@[EMAI  2008-05-09 05:07:59 
Re: compile time value -> index calculation
Christof Warlich <cwar  2008-05-09 15:06:39 
Re: compile time value -> index calculation
gnuyuva <gnuyuva@[EMAI  2008-05-10 01:33:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 0:22:38 CDT 2008.