# Include <iostream> <br/> # include <vector> <br/> # include <boost/assign. HPP> <br/> # include <boost/range/adaptor/transformed. HPP> <br/> # include <boost/spirit/include/karma. HPP> </P> <p> using namespace STD; <br/> using namespace boost: adaptors; <br/> using namespace boost: Assign; <br/> namespace karma = boost: Spirit: karma; </P> <p> int F (int x) {return x + 1 ;} </P> <p> struct x <br/> {<br/> typedef int result_type; <br/> int operator () (int x) const {return x + 1 ;}< br/>}; </P> <p> int main () <br/>{< br/> vector <int> V; <br/> V + = 1, 2, 4, 5; </P> <p> auto v2 = v | transformed (f); <br/> cout <karma :: format (karma: auto _ % ',' <'/N', V2); </P> <p> auto V3 = v | transformed (x ()); <br/> cout <karma: Format (karma: auto _ % ',' <'/N', V3 ); </P> <p> return 0; <br/>}</P> <p> //, 6 <br/> //, 6, 6# Include <iostream> <br/> # include <vector> <br/> # include <boost/assign. HPP> <br/> # include <boost/range/adaptor/transformed. HPP> <br/> # include <boost/lambda/Lambda. HPP> <br/> # include <boost/spirit/include/Phoenix. HPP> <br/> # include <boost/spirit/include/karma. HPP> <br/> # include <boost/function_types/result_type.hpp> </P> <p> using namespace STD; <br/> using namespace boost: adaptors; <br/> using namespace boost: Assign; <br/> namespace karma = boost: Spirit: karma; </P> <p> template <typename F> <br/> struct result_type_wrapper: boost: function_types: result_type <decltype (& F: Operator ()> <br/>{< br/>}; </P> <p> template <typename F> <br/> struct adaptable_wrapper: F <br/>{< br/> typedef typename result_type_wrapper <F >:: type result_type; <br/> // typedef typename boost: function_types :: result_type <decltype (& F: Operator () >:: type result_type; </P> <p> adaptable_wrapper (f): F (f) {}< br/>}; </P> <p> template <typename F> <br/> adaptable_wrapper <F> make_adaptable (f) <br/>{< br/> return adaptable_wrapper <F> (f); <br/>}</P> <p> int main () <br/>{< br/> vector <int> V; <br/> V + = 1, 2, 4, 5; </P> <p> // auto v2 = v | transformed (boost: Phoenix: arg_names: _ 1 + 1 ); // error <br/> // auto V3 = v | transformed (boost: Lambda: _ 1 + 1 ); // error <br/> // auto V4 = v | transformed ([] (int x) {return x + 1 ;}); // error </P> <p> auto V5 = v | transformed (make_adaptable ([] (int x) {return x + 1 ;})); <br/> cout <karma: Format (karma: auto _ % ',' <'/N', V5 ); </P> <p> return 0; <br/>}</P> <p> // 2, 3, 4, 5, 6