Skip to content

Instantly share code, notes, and snippets.

@spencerdeinum
Created December 30, 2013 22:50
Show Gist options
  • Save spencerdeinum/8189557 to your computer and use it in GitHub Desktop.
Save spencerdeinum/8189557 to your computer and use it in GitHub Desktop.
std::array
#include <array>
#include <iostream>
using namespace std;
template<class T, size_t Size>
T sum(array<T, Size> a)
{
T total = 0;
for(auto i : a)
{
total += i;
}
return total;
}
int main()
{
array<int, 5> integers = {{ 1, 2, 3, 4, 5 }};
array<float, 3> floats = {{ 1.5, 1.5, 0.7 }};
cout << sum(integers) << endl;
cout << sum(floats) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment