Skip to content

Instantly share code, notes, and snippets.

@saschagrunert
Last active May 13, 2018 13:44
Show Gist options
  • Save saschagrunert/8a6ecb049fef0f8f03664798b4c53e82 to your computer and use it in GitHub Desktop.
Save saschagrunert/8a6ecb049fef0f8f03664798b4c53e82 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <numeric>
#include <vector>
int main(void) {
// Create a vector
std::vector<std::string> v{"foo", "bar"};
// Fold by reference
std::string res = "";
auto res = std::accumulate(
v.begin(),
v.end(),
res,
[](std::string & acc, const std::string & val) -> std::string & {
return acc += val;
}
);
// Outputs to: "foobar"
std::cout << res << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment