Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a basic example of std::accumulate. #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

janoma
Copy link
Contributor

@janoma janoma commented Jun 2, 2016

This should take care of #62.

sum_numbers(Collection const& collection)
{
using ReturnType = typename Collection::value_type;
return std::accumulate(std::begin(collection), std::end(collection), static_cast<ReturnType>(0));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why use std::begin and std::end instead of collection.begin() and collection.end()?

Copy link
Contributor Author

@janoma janoma Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a generic free function that will call what you expect without any overload (for any decent compiler). It also support arrays, so you can call sum_numbers on an array as well. And of course you can call it with any non-STL container for which an appropriate overload of the functions has been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants