#include template int get_at (const T&, int); struct XY { int x, y; }; template <> int get_at(const int(&in)[2], int i) { return in[i]; } template <> int get_at(const XY& in, int i) { return (i ? in.y : in.x); } template struct Vec { int x() const { return get_at(m_storage_type, 0); } int y() const { return get_at(m_storage_type, 1); } T m_storage_type; }; template std::ostream& operator<< (std::ostream& os, const Vec& v) { os << '<' << v.x() << ',' << v.y() << '>'; return os; } int main() { Vec v1; Vec v2; v1.m_storage_type[0] = 1234; v1.m_storage_type[1] = 7777; v2.m_storage_type.x = 44; v2.m_storage_type.y = 9999; std::cout << v1 << '\n'; std::cout << v2 << '\n'; return 0; }