Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-08-09 07:44:27


"David B. Held" <dheld_at_[hidden]> writes:

> "Aleksey Gurtovoy" <agurtovoy_at_[hidden]> wrote in message
> news:065501c35dfb$4c6d1ea0$f944a8c0_at_metacomm.com...
>> [...]
>> typedef typename apply<
>> typename lambda<Policy>::type
>> , T
>> >::type p;
>>
>> things should work independently of whenever 'Policy' is in form of
>> 'my_policy<_>' or 'my_policy' - given that the latter is a metafunction
>> class, of course.
>
> Never mind. It all works as advertised. I thought a class only had
> to have a nested apply<> struct to be metafunction class, but it
> also needs a typedef .. type; in the *apply*. I think I tried
> putting in the type, but I put it outside of the apply, which was
> causing my problems. It seems odd that I have to say:
>
> struct Policy
> {
> template <typename P>
> struct apply
> {
> typedef apply type;
> // ...
> };
> };
>
> I guess that is to be consistent with metafunctions, but for some
> reason I thought that lambda or mpl added the type for you.

Lambda "adds the type" for cases like std::vector<_1>. Metafunction
classes, though, are supposed to be the super-efficient way to do
things, so having the library perform extra template instantiations to
detect the nested ::type would probably not be appropriate there.

BTW, normally, you might:

struct Policy
{
    template <class P>
    struct apply
    {
        typename some_other_class type;
    };
};

if nothing else, just to cut down on symbol size (you don't want to
see Policy::apply<...> in your error messages when it could be
some_other_class<...>).

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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