David A. Greene wrote:
> Aleksey Gurtovoy wrote:
> > It _is_ possible to implement a single template along the 
> > lines of the SHAZAM template you've mentioned early in the 
> > thread:
> > 
> >     template<typename T, typename U, typename V>
> >     struct my_type { ... }  // Note: no ::type member
> > 
> >     typedef SHAZAM<my_type<int, _1, _2> > generator;
> > 
> >     typedef generator::template apply<char, float>::type 
> my_type_inst;
> > 
> > but not at the user side - the library internal mechanisms 
> > needs to be made aware of it. 

Actually, I lied - on a conforming compiler you can do the following:

    template< typename T, typename U, typename V >
    struct my_type {};  // Note: no ::type member

    // declare 'my_type' a "reduced" metafunction
    REDUCED_METAFUNCTION_SPEC(3, my_type)

    // test it
    typedef lambda< my_type<int,_1,_2> >::type f;
    typedef f::apply<char,short>::type t;

    BOOST_STATIC_ASSERT((is_same< t, my_type<int,char,short> >::value));

where REDUCED_METAFUNCTION_SPEC is as simple as this:

    #define REDUCED_METAFUNCTION_SPEC(n, name) \
    namespace boost { namespace mpl { \
    template<> struct meta_fun##n< name > \
    { \
        template< BOOST_PP_ENUM_PARAMS(n, typename T) > \
        struct apply \
        { \
            typedef my_type<BOOST_PP_ENUM_PARAMS(n,T)> type; \
        }; \
    }; \
    }} \
    /**/


> > I considered this before, - as 
> > well as the option of directly supporting the "reduced" 
> > metafunction form, - and the latter is currently my
> > preference. Will see if something changes after I actually 
> > implement it (for one, it might slow down the lambda 
> > significantly, - but we'll see).
> 
> Thanks for considering this.  I think it will be quite useful.  I look
> forward to seeing what you come up with!

Well, it turned out to be a little bit more complicated than I had foreseen,
so it's not there yet. Please stay tuned!

Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to