[mpl] lazy condition in enable_if
Hi, I need to run boost::mpl::for_each<> function with template condition, like: boost::mpl::for_each< vector_of_types, boost::mpl::make_identity<boost::mpl::_1> > (Functor< condition >()); I'm trying to implement lazy binding in enable_if. Visual studio fails with error "'X<IsFoo<boost::mpl::_>>::operator ()' : ambiguous call to overloaded function" minimal test code which fail on boost 1.57 #include <boost/mpl/for_each.hpp> #include <boost/mpl/lambda.hpp> #include <boost/mpl/bind.hpp> #include <boost/mpl/vector.hpp> #include <boost/core/enable_if.hpp> #include <iostream> #include <type_traits> template <int> struct dummy { dummy(int) {} }; // from doc struct Foo {}; struct Bar {}; template <typename T> struct IsFoo { typedef typename std::is_same<T, Foo>::type type; }; #define generate_type(_fn) \ typename boost::mpl::apply<boost::mpl::bind< \ boost::mpl::lambda< _fn <boost::mpl::_> >::type, \ boost::mpl::bind<typename boost::mpl::lambda<_Pred>::type, U> \ > >::type #define enable_type generate_type(boost::enable_if) #define disable_type generate_type(boost::disable_if) template <typename _Pred> struct X { template <typename U> enable_type operator()(boost::mpl::identity<U>, dummy<0> = 0) const { std::cout << "enable: " << typeid(U).name() << std::endl; } template <typename U> disable_type operator()(boost::mpl::identity<U>, dummy<1> = 0) const { std::cout << "disable: " << typeid(U).name() << std::endl; } }; int main() { X<IsFoo<boost::mpl::_> > x; x(boost::mpl::identity<Foo>()); x(boost::mpl::identity<Bar>()); return 0; }
participants (1)
-
Sam Fisher