Last active
January 8, 2021 21:28
-
-
Save gvnwltrs/bc97711c650a4756d6714160d4a7c678 to your computer and use it in GitHub Desktop.
Adding #CPP
This file contains hidden or 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
// adding up members of a collection | |
// accumulate(); uses the '+' operator to add up all members in a collection; sum tool; another template! | |
// can also use lambdas instead | |
vector<int> a = {1, 2, 3, 4, 5}; | |
for (int i : a) | |
{ | |
total += i; | |
} | |
total = accumulate(begin(a), end(a), 0); // much better! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment