Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 21, 2012 14:34
Show Gist options
  • Select an option

  • Save yifu/3761815 to your computer and use it in GitHub Desktop.

Select an option

Save yifu/3761815 to your computer and use it in GitHub Desktop.
c++11 tests.
#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