Boost logo

Boost :

Subject: Re: [boost] metaprogramming: associating a type with another type
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2010-01-29 16:06:09


On Fri, Jan 29, 2010 at 12:47 PM, DE <satan66613_at_[hidden]> wrote:

> hi boosters
> while solving my own design problems i accidentally discovered an
> interesting technique
>
> let's assume we want to associate some value (a type) to a newly
> created type so we can easily access the associated type during
> metaprogramming
> let's call the associated type a property
> then we have the following property types: [snip]

I can see this being very useful for traits class specializations (by that I
mean the technique of using ADL to provide a type). As a practical example
of why this is convenient in practice is Boost.Fusion. As a part of the
library, there is a helper macro called BOOST_FUSION_ADAPT_STRUCT which, as
the name suggests, maps a struct to the fusion random access sequence
concept. When using the macro you have to do so at global scope since it has
to specialize templates in a boost namespace. If, instead, the default
definitions of these templates being specialized were altered to use an ADL
trick, you could easily create a BOOST_FUSION_ADAPT_STRUCT macro that were
usable from within the namespace itself. You'd no longer have to leave the
namespace simply to use the macro. All fusion would have to do is declare a
dummy "no_specialization get_traits(...);" kind of function in its own
namespace, then have the default definition of its traits detect if the
return type of a call to it using the specified type is "no_specialization".
If not, that means that traits were provided by the type via ADL and can be
used accordingly.

Really, it would be convenient if all traits templates used this technique.

-- 
-Matt Calabrese

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