Boost logo

Boost Users :

From: Noel Yap (yap_noel_at_[hidden])
Date: 2002-05-06 08:40:47


--- hicks <hicks_at_[hidden]> wrote:
> Query regarding the use/limitiations of traits in
> metaprogramming
>
> I am trying to use traits pattern to assist in
> metaprogramming.
> I have the following problem.
>
> A traits class "trait" defers a decision to another
> traits class
> "trait1" depending
> on the result of a third traits class "traita".
> However, the compiler does not cooperate.
> The code below excutes but gives unexpected output
> (also shown).
>
> [Note:: The code has been reduced to the minimal to
> demonstrate the problem.
> I have a real task at hand not shown here.]
>
> template <class T>
> struct traita { BOOST_STATIC_CONSTANT(int, value=0);
> };
> template <>
> struct traita<int> { BOOST_STATIC_CONSTANT(int,
> value=1); };
>
> template <class T, int>
> struct trait1 {};
>
>
> template <class T>
> struct trait
> {
> BOOST_STATIC_CONSTANT(int,
> value=traita<T>::value);
> typedef trait1<T, value> t1;
> };
>
>
>
> int main(int argc, char* argv[])
> {
> std::cout
> << typeid(trait<int>::t1).name()
> << std::endl
> << trait<int>::value
> << std::endl
> ;
> return 0;
> }
>
> output::
>
> trait1<int,0>
> 1
>
> It would be nice if the first line of output were
> "trait1<int, 1>", but
> it isn't.
>
> Any assistance would be greatly appreciated.

I have some questions for you:
1. Why are you so interested in the value of
"typeid.name()"?
2. Are you sure this isn't a compiler problem? What
compiler(s) have you tried this on?

Noel

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net