Think about it a little differently, but the goals will be achieved, add an external interface - I mean the stand-alone functions X (), Y (), Z ():
template<class T, size_t S> T& x(Vector<T, S>& obj, typename std::enable_if<(S>=1)>::type* = nullptr) { return obj.data[0]; } template<class T, size_t S> T& y(Vector<T, S>& obj, typename std::enable_if<(S>=2)>::type* = nullptr) { return obj.data[1]; } template<class T, size_t S> T& z(Vector<T, S>& obj, typename std::enable_if<(S>=3)>::type* = nullptr) { return obj.data[2]; }
There is not much difference between:
Vector<T, 3>& obj return obj.x();
and
Vector<T, 3>& obj return x(obj);
As a bonus, this interface works to fit the size.
source share