|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-12-05 12:06:27
"David A. Greene" <greened_at_[hidden]> writes:
> [Posted to boost because MPL is not yet released. At what
> point should these questions go to boost-users?]
>
> Say I have a type my_type:
>
> template<typename T, typename U, typename V>
> struct my_type { ... }
>
> Now let's say I want to create a generator that
> binds T to some type but leaves U and V free to
> be filled in later. Basically, I want something
> like this:
>
> template<typename Bound>
> struct my_type_generator {
> template<typename U, typename V>
> struct apply {
> typedef my_type<Bound, U, V> type;
> };
> };
Looks good to me.
> Is there a convenient way to create this with MPL?
You want it to be more convenient than that?!
template <class T, class U, class V>
struct my_type_generator
{
typedef my_type<T,U,V> type;
};
lambda<my_type_generator> does it, unless of course your compiler
needs BOOST_MPL_AUX_LAMDA_SUPPORT.
I don't think it's much of a savings, though.
> I thought lambda might do the trick, but apparently not:
>
> typedef my_type<int, mpl::_1, mpl::_2> my_type_generator;
>
> (This will be passed to an MPL algorithm so I didn't
> bother with lambda<>).
>
> This causes a static assertion in mpl::arg<2> where it
> sees a void type for V (I think).
>
> Is the problem that my_type doesn't contain a ::type
> member?
Maybe. What compiler are you using?
> my_type is not a metafunction so maybe it just can't be used
> conveniently with mpl. It's easy enough to manually define
> my_type_generator, but I think this is a pretty common pattern and
> it might be useful as a library component.
Hmmmm...
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk