[NO-PARSE]#include <iostream>
#include <vector>
template <typename T, int length>
struct vec
{
vec(std::vector<T> &v) : data(&v) { }
std::vector<T> &values() const { return *data; }
std::vector<T> *data;
};
template <typename T, int length>
vec<T, length> &operator+=(vec<T, length> &lhs, const vec<T, length> &rhs)
{
for (int i = 0; i < length; ++i)
lhs.values() += rhs.values();
return lhs;
}
int main()
{
std::vector<int> v = { 1, 2, 3 };
// check contents of v beforehand
std::cout << "Contents of 'v':\n\t";
for (const auto &it : v)
std::cout << it << ' ';
std::cout << '\n';
vec<int, 3> obj(v); // construct a object grabbing pointer from v
obj += obj; // add object constructed from v2 to previous object
// values contained within vector pointed to within obj
std::cout << "Contents of dereferenced 'obj' internal pointer:\n\t";
for (const auto &it : obj.values())
std::cout << it << ' ';
std::cout << '\n';
// values contained within v
std::cout << "Contents of 'v':\n\t";
for (const auto &it : v)
std::cout << it << ' ';
std::cout << '\n';
}[/NO-PARSE]