1.
- #include <iostream>
- #include <vector>
- #include <boost/assign.hpp>
- #include <boost/range/adaptor/transformed.hpp>
- #include <boost/spirit/include/karma.hpp>
-
- using namespace std;
- using namespace boost::adaptors;
- using namespace boost::assign;
- namespace karma = boost::spirit::karma;
-
- int f(int x) {return x + 1;}
-
- struct X
- {
- typedef int result_type;
- int operator()(int x) const {return x + 1;}
- };
-
- int main()
- {
- vector<int> v;
- v += 1,2,3,4,5;
- auto v2 = v | transformed(f);
- cout << karma::format(karma::auto_ % ',' << '\n', v2);
- auto v3 = v | transformed(X());
- cout << karma::format(karma::auto_ % ',' << '\n', v3);
- return 0;
- }
2.
- #include <iostream>
- #include <vector>
- #include <boost/assign.hpp>
- #include <boost/range/adaptor/transformed.hpp>
- #include <boost/lambda/lambda.hpp>
- #include <boost/spirit/include/phoenix.hpp>
- #include <boost/spirit/include/karma.hpp>
- #include <boost/function_types/result_type.hpp>
-
- using namespace std;
- using namespace boost::adaptors;
- using namespace boost::assign;
- namespace karma = boost::spirit::karma;
-
- template<typename F>
- struct result_type_wrapper : boost::function_types
- ::result_type<decltype(&F::operator())>
- {
- };
-
- template<typename F>
- struct adaptable_wrapper : F
- {
- typedef typename result_type_wrapper<F>::type result_type;
-
-
-
- adaptable_wrapper(F f) : F(f) {}
- };
-
- template<typename F>
- adaptable_wrapper<F> make_adaptable(F f)
- {
- return adaptable_wrapper<F>(f);
- }
-
- int main()
- {
- vector<int> v;
- v += 1,2,3,4,5;
-
-
-
-
-
- auto v5 = v | transformed(make_adaptable([](int x){return x + 1;}));
- cout << karma::format(karma::auto_ % ',' << '\n', v5);
- return 0;
- }
-
(zwvista) |