Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <iomanip>
- #include <functional>
- #include <iterator>
- #include <list>
- template<typename RET_CONT, typename IT, typename OPERATION>
- RET_CONT map(IT begin, IT end, OPERATION op)
- {
- RET_CONT ret;
- std::transform(begin, end, back_inserter(ret), op);
- return ret;
- }
- int main()
- {
- auto println = [](const char *message) { std::cout << "\n" << message << '\n'; };
- std::vector<int> col{ 23, 23, 37, 42, 23, 23, 37 };
- typedef std::vector<double> astype;
- auto func = [] (auto i) {
- return i * 10.0;
- };
- astype out = map<astype>(col.begin(), col.end(), func);
- std::copy(out.begin(), out.end(), std::ostream_iterator<decltype(out.at(0))>(std::cout, " "));
- return 0;
- }
Add Comment
Please, Sign In to add comment