Boost logo

Boost :

Subject: Re: [boost] Boost MPL metafunction shortcut
From: Agustín Bergé (kaballo86_at_[hidden])
Date: 2011-04-09 20:36:48


On 09/04/2011 16:48, Joel Falcou wrote:
> I was thinking lately that it is a shame we can't do the following :
>
> boost::mpl::transform< SomeSequence, _1&>
>
> instead of the lengthy
>
> boost::mpl::transform< SomeSequence, add_reference<_1> >
>
> same goes for *, const, volatile :
>
> boost::mpl::transform< SomeSequence, volatile _1**&>
>

Some time ago I did some work on a metafunction to perform overload
resolution. In the process of emulating and supporting template
functions, I ended up with something I like to call 'type patterns' as a
byproduct. It allows to query as well as create types based on 'type
patterns', as the OP suggest, in a less verbose way. For example:

matches< int( _1, _, _1 ), T >::type

is T a function type returning int, taking three parameters, where the
first and the last one are of the same type, and the second one is of
any type? If so, which type is _1?

replace< int( _1, _2, _1 ), list< int, float > >::type

create a function type with signature int( int, float, int )

The core of it is a metafunction that decomposes the type declaration
into an AST, and applies a visitor function to it. AFAIR, it considered
const and volatile modifiers, pointers and references, arrays, pointers
to member, function types, and even templates.

Perhaps its time for me to dig such code, and polish it up to boost
standards. Would it be interest in adding something like this to MPL?

Agustín K-ballo Bergé.-
http://talesofcpp.blogspot.com


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