Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-01-12 04:54:35


Jaap Suter wrote:
> So I tried to come up with the actual smallest example that
> doesn't compile, even
> with the LAMBDA_SUPPORT macro. It looks as follows:
>
> template< class T >
> struct meta_fun_1
> {
> typedef mpl::integral_c< typename T::value_type, 0 > type;
> BOOST_MPL_AUX_LAMBDA_SUPPORT( 1, meta_fun_1, (T) )
> };
>
> template< class List, class T >
> struct meta_fun_2
> {
> typedef typename mpl::fold< List,
> mpl::integral_c< size_t, 0 >,
> meta_fun_1< mpl::_1 >
> >::type type;
> };
>
> The problem lies in the fact that I try to use a dependent type in
> meta_fun_1.

Yep, to be concrete, 'T::value_type'. Please see the following posts for an
explanation of the shortcoming, as well as for a technique to work around
it:

http://lists.boost.org/MailArchives/boost/msg39915.php (the relevant part
starts from "Well, having said that..." paragraph)
http://lists.boost.org/MailArchives/boost/msg39930.php (further explanation)

> I have pasted the full compiler error at the bottom of the
> message (it's rather long). The first few lines say:
>
> 'value_type' : is not a member of 'boost::mpl::arg<N>'
> with
> [
> N=1
> ]
> <snip>
> e:\library\boost_1_29_0\boost\type_traits\is_convertible.hpp(61) : see
> reference to class template instantiation 'test::meta_fun_1<T>' being
> compiled
> with
> [
> T=boost::mpl::_1
> ]
>
> Any suggestions? I can work-around it by using plain integers
> instead of ::value_type, but it's not as elegant.

    template< class T >
    struct meta_fun_1_impl
    {
        typedef mpl::integral_c< typename T::value_type, 0 > type;
    };

    template< class T >
    struct meta_fun_1
        : mpl::if_<
              mpl::is_placeholder<T>
            , mpl::identity<T>
            , meta_fun_1_impl<T>
>::type
    {
        BOOST_MPL_AUX_LAMBDA_SUPPORT( 1, meta_fun_1, (T) )
    };

Or, if it's an internal/helper metafunction, just re-write it as a
metafunction class and, if you need to bind parameters to it - well, just
use 'bind':

    typedef fold< types, int_c<0>, bind<tenary_meta_fun_class, _1 ,_2, int>
>::type res;

A.


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