Boost logo

Boost :

Subject: Re: [boost] metaprogramming: associating a type with another type
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2010-01-29 13:12:17


DE wrote:
> hi boosters
> while solving my own design problems i accidentally discovered an
> interesting technique
>...
> template<typename t>
> struct property {
> typedef typeof(get_prop((type*)42) type;
> };

This here makes no sense. The property template does not depend on t and the typedef is cyclicly defined. I'm guessing you intended:

   template<typename t>
   struct property {
     typedef typeof(get_prop((t*)42) type;
   };

But even so I don't quite understand what you're driving at because you never use the property template in your example. It the point that you never have to specialize traits for the property type of a class that derives from base? Isn't deriving from base a stronger requirement than the specialization of a metafunction?

I'm also confused by this:

> template<typename type, typename p = typename property<type>::type>
> struct base {
> friend p get_prop(type*) { return p(); }
> };

property<type>::type will always return property0. Is your intention that people fully specialize property<> for their type to override the default behavior, or to specialize get_prop<>? Since I'm not sure what your goal is I can't say there is anything wrong with your design, but it seems to me that there are elements of your design that serve no obvious function. Perhaps you can provide a larger example to make the benefit of your approach clearer to those of us who haven't finished our morning coffee yet.

Thanks,
Luke


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk