At first I thought it was a C ++ question for some reason!
If you can use C ++, you can use an STL array (where size is a template parameter, not a stored value).
It might look something like this:
std::array<double, 7> a = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
std::array<double, 7> b = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
auto c = a + b;
auto d = a + b + c;
+. :
#include <array>
template <class T, size_t size>
std::array<T, size> operator+(const std::array<T, size>& a,
const std::array<T, size>& b)
{
std::array<T, size> c;
for (size_t i = 0; i < size; ++i)
{
c[i] = a[i] + b[i];
}
return c;
}
template <class T, size_t size>
std::array<T, size>&& operator+(std::array<T, size>&& a,
const std::array<T, size>& b)
{
for (size_t i = 0; i < size; ++i)
{
a[i] += b[i];
}
return std::move(a);
}
:
auto c = a + b;
auto d = a + b + c;
.
std:: array , , "" ( (ab) , typedefs ) .