
Angus Leeming wrote:
Even if this turns out to be impossible, I'd like to go on and try to define some_boolean_condition if I may. I see that Aleksey plans a contains_c metafunction for 1.33,
Apologies for replying to self, but I have managed to define a contains_c metafunction. (Below). I still don't know how to use it with enable_if, however. This fails to compile: boost::enable_if< mpl::contains_c< mpl::vector_c< int, foo::state2, foo::state3 > , foo::state2 > , foo::state
::type s = foo::state2;
My naïve understanding is that enable_if<...>::type should be foo::state here. Any pointers? Regards, Angus #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_same.hpp> #include <boost/mpl/assert.hpp> #include <boost/mpl/deref.hpp> #include <boost/mpl/end.hpp> #include <boost/mpl/equal_to.hpp> #include <boost/mpl/find_if.hpp> #include <boost/mpl/lambda.hpp> #include <boost/mpl/integral_c.hpp> #include <boost/mpl/not.hpp> #include <boost/mpl/vector_c.hpp> namespace boost { namespace mpl { template <typename IntegralSequence, int Value> struct contains_c { private: typedef typename find_if< IntegralSequence , equal_to< _1 , integral_c<typename IntegralSequence::value_type, Value> > >::type iter; public: typedef typename not_< is_same< iter , typename end<IntegralSequence>::type > >::type type; typedef typename type::value_type value; }; } // namespace mpl } // namespace boost class foo { public: enum state { state1, state2, state3 }; }; int main() { namespace mpl = boost::mpl; typedef mpl::vector_c< int, foo::state2, foo::state3 > allowable_values; // Fails to compile, as expected. // BOOST_MPL_ASSERT(( mpl::contains_c< allowable_values, foo::state1 > )); // Compiles, as expected. BOOST_MPL_ASSERT(( mpl::contains_c< allowable_values, foo::state2 > )); // Why doesn't this compile? boost::enable_if< mpl::contains_c< allowable_values, foo::state2 > , foo::state >::type s = foo::state2; return 0; }