diff --git a/OgreMain/include/OgreVector.h b/OgreMain/include/OgreVector.h index c42360a1bc2..22d407807e5 100644 --- a/OgreMain/include/OgreVector.h +++ b/OgreMain/include/OgreVector.h @@ -64,6 +64,11 @@ namespace Ogre T data[dims]; T* ptr() { return data; } const T* ptr() const { return data; } + /** to help make VectorBase enum-like */ + template T get() { + static_assert(N < dims); + return data[N]; + } }; template <> struct _OgreExport VectorBase<2, Real> { @@ -72,6 +77,10 @@ namespace Ogre Real x, y; Real* ptr() { return &x; } const Real* ptr() const { return &x; } + template Real get() { + static_assert(N < 2); + return (&x)[N]; + } /** Returns a vector at a point half way between this and the passed in vector. @@ -132,6 +141,10 @@ namespace Ogre Real x, y, z; Real* ptr() { return &x; } const Real* ptr() const { return &x; } + template Real get() { + static_assert(N < 3); + return (&x)[N]; + } /** Calculates the cross-product of 2 vectors, i.e. the vector that lies perpendicular to them both. @@ -261,6 +274,10 @@ namespace Ogre Real x, y, z, w; Real* ptr() { return &x; } const Real* ptr() const { return &x; } + template Real get() { + static_assert(N < 4); + return (&x)[N]; + } // special points static const Vector4 ZERO; @@ -885,4 +902,24 @@ namespace Ogre /** @} */ } + +//define the required std features to make VectorBase tuple-like +//thus allowing structured bindings for Vector. +namespace std { + template + struct tuple_size> : std::integral_constant {}; + template + struct tuple_size> : std::integral_constant {}; + + template + struct tuple_element> { + using type = T; + }; + + template + struct tuple_element> { + using type = T; + }; +} + #endif