Skip to content

Instantly share code, notes, and snippets.

@sailfish009
Created January 30, 2019 08:34
Show Gist options
  • Save sailfish009/97572e3d0e55028df7f34a20534fe71c to your computer and use it in GitHub Desktop.
Save sailfish009/97572e3d0e55028df7f34a20534fe71c to your computer and use it in GitHub Desktop.
https://stackoverflow.com/questions/7213839/equivalent-in-c-of-yield-in-c
https://ideone.com/SQZ1qZ
#include <iostream>
int main()
{
auto&& function = []()
{
int i = 0; return [=]() mutable { int arr[] = {1,2,4,8,16,16777216}; if ( i < 6 ) return arr[i++]; return 0; };
}();
for ( unsigned long i = 0; i != 10; ++i )
std::cout << "\t" << function() << "\t|";
std::cout << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment