Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-08-29 07:32:16


Ben Hutchings <ben.hutchings_at_[hidden]> writes:

> Alan M. Carroll wrote:
>
>> typedef typename boost::mpl::if_c<IS_OUTER,
>> typename PAYLOAD::key_type,
>> PAYLOAD
>> >::type testing;
>
> That can't work. All the template arguments to boost::mpl::if_c must be
> syntactically valid after substiution of C's template parameters, and
> clearly that won't be the case. I think you need to write your own
> selection template:
>
> template<typename T, bool> struct type_or_key_type
> { typedef T type; };
> template<typename T> struct type_or_key_type<T, true>
> { typedef typename T::key_type type; };
>
> then use
>
> typedef typename type_or_key_type<PAYLOAD, IS_OUTER>::type testing;

I'd normally solve it this way:

    template <class T> struct key_type
    {
        typedef typename T::key_type type;
    };

    typedef mpl::eval_if_c<
        IS_OUTER
      , key_type<PAYLOAD>
      , mpl::identity<PAYLOAD>
>::type testing;

HTH,

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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net