codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <tr1/functional> using std::list; using std::tr1::function; template<typename a, typename b> list<b> mymap(function<b(a)> f, list<a> x) { list<b> y; std::transform(x.begin(), x.end(), std::back_inserter(y), f); return y; } double the_f(int i) { return i / 2.; } int main() { list<int> x; x.push_back(3); x.push_back(9); function<double(int)> f = the_f; list<double> y = mymap(f, x); std::cout << y; }
Private
[
?
]
Run code
Submit