Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2005-08-25 21:09:13


OK, I worked it out. I couldn't get this to compile:

         typedef typename boost::mpl::if_c<IS_OUTER,
                  typename PAYLOAD::key_type,
                 PAYLOAD
        >::type testing;

The problem is that I can't have the type specification PAYLOAD::key_type, it has to be disconnected to allow lazy evaluation to work. The following compiles and works:

        template < bool F , typename T >
        struct get_key_type_if { typedef typename T type; };
        template < typename T >
        struct get_key_type_if<true, T> { typedef typename T::key_type type; };

         typedef typename get_key_type_if<IS_OUTER, PAYLOAD>::type testing;

Ah, finally, I have an MPL variant that works:

        
struct get_key_type { template < typename T > struct apply { typedef typename T::key_type type; }; };
        
typedef typename boost::mpl::eval_if_c<IS_OUTER,
                 
typename boost::mpl::apply<get_key_type, PAYLOAD>,
                 
typename boost::mpl::identity<PAYLOAD>
        >::type testing;

Is this as simple as it gets?


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