Created
July 3, 2020 14:09
-
-
Save JohnMurray/6b35f7acc93a4da96ed8431347ee9026 to your computer and use it in GitHub Desktop.
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 <algorithm> | |
#include <functional> | |
#include <vector> | |
int main() { | |
std::function<int(int)> addOne = [](int x) -> int { | |
return x + 1; | |
}; | |
addOne(5); | |
// returns 6 | |
// use lambda as value, do in-place modification | |
std::vector<int> v = {1, 2, 3, 4, 5}; | |
std::transform(v.begin(), v.end(), v.begin(), | |
addOne); | |
// new value of 'v' is [2, 3, 4, 5, 6] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment