Instantly share code, notes, and snippets.

What would you like to do?
std::array<char, 5> ys{ 'A', 'B', 'C', 'D', 'E' };
std::string s_initial = "";
//fold/left fold
std::string s_total = std::accumulate(ys.begin(), ys.end(), s_initial);
std::cout << s_total << "\n"; //ABCDE
s_initial = "";
//fold back/right fold
s_total = std::accumulate(ys.rbegin(), ys.rend(), s_initial);
std::cout << s_total << "\n"; //EDCBA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment