
I want to apply some arbitrary function F on each element of a sequence through myfun class inherited from transform_view. I am unable to output the elements of the resultant sequence. Below is the whole code of my program #include <boost/mpl/int.hpp> #include <boost/mpl/apply.hpp> #include <boost/mpl/list_c.hpp> #include <boost/mpl/for_each.hpp> #include <boost/mpl/transform_view.hpp> #include <iostream> using namespace boost::mpl; namespace mpl = boost::mpl; struct mysquare { template< typename U > void operator()(U x) { static const int value = x*x; } }; struct value_printer { template< typename U > void operator()(U x) { std::cout << x << " "; } }; template<class F, class Seq> struct myfun:transform_view<Seq,F> {}; int main() { using namespace std; typedef list_c<int,0,1,2,3,4,5> numbers; typedef myfun<mysquare,numbers>::type newnum; for_each<numbers>(value_printer()); // for_each<newnum>(value_printer()); // I don,t know what transform_view return }

AMDG noman javed wrote:
I want to apply some arbitrary function F on each element of a sequence through myfun class inherited from transform_view. I am unable to output the elements of the resultant sequence. Below is the whole code of my program
mpl::transform_view takes an MPL lambda expression rather than a function object, because it operates on types, not objects. (most MPL constructs take lambda expressions--mpl::for_each is a special case) #include <boost/mpl/times.hpp> ... typedef myfun<mpl::times<mpl::_1, mpl::_1>,numbers>::type newnum; In Christ, Steven Watanabe
participants (2)
-
noman javed
-
Steven Watanabe