Created
September 21, 2012 14:34
-
-
Save yifu/3761815 to your computer and use it in GitHub Desktop.
c++11 tests.
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 <iostream> | |
| using namespace std; | |
| /* Test the lambda feature from c++11 */ | |
| /* /Soft/mag/dev/tools/gcc-4.7.1/bin/g++ --std=c++11 lambdas.cpp && ./a.out */ | |
| int main() | |
| { | |
| cout << "hello world." << endl; | |
| int i = 3; | |
| // When not mutable, this is a stateless functor. | |
| auto e = [=] /*() mutable*/ { cout << "hello world from a non mutable lambda [" << i << "]. " << endl; }; | |
| e(); e(); e(); | |
| // When declared mutable, you must introduce an empty parameter list! | |
| auto f = [=] () mutable { cout << "hello world from a lambda [" << i++ << "]. " << endl; }; | |
| f(); f(); f(); f(); f(); f(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment