Skip to content

Instantly share code, notes, and snippets.

@apathyboy
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save apathyboy/0f9f9431749d9370f611 to your computer and use it in GitHub Desktop.

Select an option

Save apathyboy/0f9f9431749d9370f611 to your computer and use it in GitHub Desktop.
#include <functional>
#include <iostream>
#include <vector>
int main() {
// initialize vector to hold 1000 elements
std::vector<std::function<int(int)>> v1;
// fill the vector with 1000 lamdas
for (auto i = 0; i < 1000; ++i)
v1.push_back([i](int n) { return n + i; });
auto j = 0;
// call all of the lamdas
for (auto &func : v1)
j = func(j);
// output the result
std::cout << "Result j = " << j << std::endl;
return 0;
}
$ time make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/projects/lambdas/build-clang
[100%] Building CXX object CMakeFiles/lamdas-std.dir/std_function.cpp.o
Linking CXX executable lamdas-std
[100%] Built target lamdas-std
real 0m0.836s
user 0m0.720s
sys 0m0.084s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment