Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-08-26 08:37:36

Alan M. Carroll wrote:

> I must be missing something obvious, or Boost.Mpl doesn't work on MSVC
> 7.1.
> I'm working on my container class C<METRIC, PAYLOAD>. Using MPL I've
> defined a class static bool IS_OUTER which, if true, means that
> PAYLOADhas a typedef for the name "key_type". If IS_OUTER is false,
> then PAYLOADmay not have such a typedef (and in my test case, it
> doesn't). What I want to do, in C, is have a typedef that is
> PAYLOAD::key_type if IS_OUTER is true and just plain PAYLOAD if
> IS_OUTER is false. I cannot make it work. I've checked IS_OUTER and it
> has the correct value. But no matter what combination of if_c,
> eval_if_c, apply, etc. I use it won't compile because "'key_type' : is
> not a member of". Here's my basic example without the elaboration:
> typedef typename boost::mpl::if_c<IS_OUTER,
> typename PAYLOAD::key_type,
> >::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;


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at