c++ - MPL for_each to use functor with more parameters -
i want utilize compile time (mpl) for_each check if given input variable in mpl array , , output variable mpl array again. i'm trying utilize function object 2 parameters mpl type , input.
#include <boost/mpl/list.hpp> #include <algorithm> #include <boost/mpl/for_each.hpp> #include <string> #include <istream> #include <ostream> #include <sstream> #include <boost/mpl/range_c.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/vector_c.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/bind.hpp> using namespace std; namespace mpl = boost::mpl; typedef mpl::range_c<char,1,5> range5; typedef mpl::list< mpl::int_<1> , mpl::int_<5> , mpl::int_<31> , mpl::int_<14> , mpl::int_<51> > out_type; template <class t> struct id {}; struct do_this_wrapper { static char stat_c ; template<typename u> inline void operator()(int i, u ) { if (i == u::value) { do_this_wrapper::stat_c = mpl::at_c<out_type,u::value>::type::value; } } }; char do_this_wrapper::stat_c ; int main() { int x =1; boost::mpl::for_each<range5>(boost::bind(do_this_wrapper(), x, _1)); homecoming 0; };
these errors
in file included /usr/include/boost/bind.hpp:22:0, ../src/testproj3.cpp:2627: /usr/include/boost/bind/bind.hpp: in instantiation of ‘struct boost::_bi::result_traits<boost::_bi::unspecified, do_this_wrapper>’: /usr/include/boost/bind/bind_template.hpp:15:48: required ‘class boost::_bi::bind_t<boost::_bi::unspecified, do_this_wrapper, boost::_bi::list2<boost::_bi::value<int>, boost::arg<1> > >’ ../src/testproj3.cpp:2665:70: required here /usr/include/boost/bind/bind.hpp:69:37: error: no type named ‘result_type’ in ‘struct do_this_wrapper’ typedef typename f::result_type type; ^ in file included ../src/testproj3.cpp:2617:0: /usr/include/boost/mpl/for_each.hpp: in instantiation of ‘static void boost::mpl::aux::for_each_impl<false>::execute(iterator*, lastiterator*, transformfunc*, f) [with iterator = boost::mpl::r_iter<mpl_::integral_c<char, '\001'> >; lastiterator = boost::mpl::r_iter<mpl_::integral_c<char, '\005'> >; transformfunc = boost::mpl::identity<mpl_::na>; f = boost::_bi::bind_t<boost::_bi::unspecified, do_this_wrapper, boost::_bi::list2<boost::_bi::value<int>, boost::arg<1> > >]’: /usr/include/boost/mpl/for_each.hpp:101:97: required ‘void boost::mpl::for_each(f, sequence*, transformop*) [with sequence = boost::mpl::range_c<char, '\001', '\005'>; transformop = boost::mpl::identity<mpl_::na>; f = boost::_bi::bind_t<boost::_bi::unspecified, do_this_wrapper, boost::_bi::list2<boost::_bi::value<int>, boost::arg<1> > >]’ /usr/include/boost/mpl/for_each.hpp:111:38: required ‘void boost::mpl::for_each(f, sequence*) [with sequence = boost::mpl::range_c<char, '\001', '\005'>; f = boost::_bi::bind_t<boost::_bi::unspecified, do_this_wrapper, boost::_bi::list2<boost::_bi::value<int>, boost::arg<1> > >]’ ../src/testproj3.cpp:2665:71: required here /usr/include/boost/mpl/for_each.hpp:75:25: error: no match phone call ‘(boost::_bi::bind_t<boost::_bi::unspecified, do_this_wrapper, boost::_bi::list2<boost::_bi::value<int>, boost::arg<1> > >) (mpl_::integral_c<char, '\001'>&)’ aux::unwrap(f, 0)(boost::get(x));
i inquire possible utilize in way , how
you should implement boost_result_of protocol do_this_wrapper
:
typedef void result_type;
see live on coliru
#include <boost/mpl/list.hpp> #include <algorithm> #include <boost/mpl/for_each.hpp> #include <string> #include <istream> #include <ostream> #include <sstream> #include <boost/mpl/range_c.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/vector_c.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/bind.hpp> using namespace std; namespace mpl = boost::mpl; typedef mpl::range_c<char,1,5> range5; typedef mpl::list< mpl::int_<1> , mpl::int_<5> , mpl::int_<31> , mpl::int_<14> , mpl::int_<51> > out_type; template <class t> struct id {}; struct do_this_wrapper { typedef void result_type; static char stat_c ; template<typename u> inline void operator()(int i, u ) { if (i == u::value) { do_this_wrapper::stat_c = mpl::at_c<out_type,u::value>::type::value; } } }; char do_this_wrapper::stat_c ; int main() { int x =1; boost::mpl::for_each<range5>(boost::bind(do_this_wrapper(), x, _1)); homecoming 0; };
c++ boost
No comments:
Post a Comment