Last active
August 8, 2018 19:31
-
-
Save cqfd/5b43c4585145eb5058aa8361d7cdd620 to your computer and use it in GitHub Desktop.
Fun C++ lambda example
This file contains 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> | |
int g = 0; | |
auto f = [g=g](auto x) mutable { | |
static auto count = 0; | |
std::cout << "count: " << ++count << std::endl; | |
std::cout << "g: " << ++g << std::endl; | |
}; | |
int main() { | |
f(1); | |
f(2); | |
f(3.0f); | |
f(4.0f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment