Last active
August 29, 2015 14:22
-
-
Save apathyboy/0f9f9431749d9370f611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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