Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-07-11 16:34:50


"Drazen DOTLIC" <Drazen.Dotlic_at_[hidden]> writes:

> Blatant copy from your mail plus small typo (size_t_c to size_t only)
> corrected:
>
> template <class S, class N>
> struct type_at_non_strict
> : mpl::apply_if<
> mpl::greater<mpl::size<S>,N>
> , mpl::at<S,N>
> , mpl::identity<mpl::void_>
> >
> {};
>
> template <class S, std::size_t N>
> struct type_at_non_strict_c
> : type_at_non_strict<S, mpl::size_t<N> >
> {};
>
> If I do not replace identity with void_ only, I get the following (nice
> VC71 elaborate error report):

That's because void_ is for MPL internal use only; it's not a type
you should manipulate (I think Aleksey doesn't believe me, but I'm
about to prove it... <wink>).

Observe the definition of identity (comments added for exposition
purposes):

template<typename T = void_>
struct identity
{
    typedef T type;
};

// identity<void_> is a metafunction class which makes it efficient
// to pass mpl::identity<> where a lambda expr/metafunction class is
// expected.
template<>
struct identity< void_ >
{
    template<
        class T1, class T2 =void_, class T3 =void_, class T4 =void_, class T5 =void_
>
    struct apply
      : identity< T1 >
    {};
};

// specialization of lambda<identity<> > for efficiency.
template<>
struct lambda< identity< void_ > >
{
    typedef identity< void_ > type;
};

-- 
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