Created
July 12, 2016 19:47
-
-
Save andrey-malets/bbf4a90f99f0d0600270c32e8ac98d6b to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <vector> | |
template<class It> typename It::value_type sum(It begin, It end) { | |
typename It::value_type res = 0; | |
while (begin != end) | |
res += *begin++; | |
return res; | |
} | |
int main(void) { | |
int a[] = {0, 1, 2, 3, 4, 5}; | |
size_t size = sizeof(a) / sizeof(a[0]); | |
std::cout << sum(a, a + size) << std::endl; | |
std::vector<int> v(a, a + size); | |
std::cout << sum(v.begin(), v.end()) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment