diff --git a/README.md b/README.md index a6ef0da..fd571f3 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you //Include Vec's header #include "vectorwrapper.hpp" #include - #include + #include template <> struct VectorWrapperInfo> { @@ -74,7 +74,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you //This will make the xy(), xz() and yz() methods available typedef std::array lower_vector_type; - scalar_type& get_at (size_t parIndex, vector_type& parVector) { + static scalar_type& get_at (size_t parIndex, vector_type& parVector) { //parIndex is already asserted to be < dimensions //so you can always assume it's valid. return parVector[parIndex]; @@ -92,7 +92,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you typedef std::array higher_vector_type; typedef std::array lower_vector_type; - scalar_type& get_at (size_t parIndex, vector_type& parVector) { + static scalar_type& get_at (size_t parIndex, vector_type& parVector) { return parVector[parIndex]; } }; @@ -108,7 +108,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you typedef float vector_type; typedef std::array higher_vector_type; - scalar_type& get_at (size_t, vector_type& parVector) { + static scalar_type& get_at (size_t, vector_type& parVector) { return parVector; } }; @@ -131,7 +131,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you //certain casts that would be disabled if you provided //the get_at() method instead. enum { - offset_x = offestof(Ogre::Vector3, x), + offset_x = offsetof(Ogre::Vector3, x), offset_y = offsetof(Ogre::Vector3, y), offset_z = offsetof(Ogre::Vector3, z) }; @@ -148,7 +148,7 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you typedef Ogre::Vector3 higher_vector_type; enum { - offset_x = offestof(Ogre::Vector3, x), + offset_x = offsetof(Ogre::Vector3, x), offset_y = offsetof(Ogre::Vector3, y) }; }; @@ -161,4 +161,4 @@ In this example we will adapt `std::array` and `Ogre::VectorN`. In you ## Limitations ## * 4D vectors are not currently supported -* Read-only vectors are not supported (not sure if such a thing is really needed) \ No newline at end of file +* Read-only vectors are not supported (not sure if such a thing is really needed) diff --git a/include/vectorwrapper/vectorwrapper.hpp b/include/vectorwrapper/vectorwrapper.hpp index 3a7a607..ff355c4 100644 --- a/include/vectorwrapper/vectorwrapper.hpp +++ b/include/vectorwrapper/vectorwrapper.hpp @@ -35,7 +35,7 @@ namespace vwr { namespace implem { define_has_typedef(lower_vector_type, LowerVec); define_has_typedef(higher_vector_type, HigherVec); - define_has_enum(vector_x, VectorX); + define_has_enum(offset_x, OffsetX); define_has_method(get_at, GetAt); template @@ -77,9 +77,9 @@ namespace vwr { struct have_same_layout { enum { value = - HasVectorXEnum::value and HasVectorXEnum::value and + HasOffsetXEnum::value and HasOffsetXEnum::value and VectorWrapperInfo::dimensions == VectorWrapperInfo::dimensions and - have_same_offsets::value; + have_same_offsets::value }; }; @@ -102,7 +102,8 @@ namespace vwr { }; VecBase ( void ) = default; - explicit VecBase ( scalar_type parInit ); + template + explicit VecBase ( const typename std::enable_if::value and not std::is_same::value, T>::type& parInit ); explicit VecBase ( const vector_type& parInit ); template VecBase ( scalar_type parX, scalar_type parY, Args... parArgs ); @@ -152,7 +153,7 @@ namespace vwr { const std::array offsets; }; - template >::value and std::is_standard_layout::vector_type>::value> + template >::value and std::is_standard_layout::vector_type>::value> class VecGetter; template struct VecGetter { @@ -162,7 +163,8 @@ namespace vwr { struct VecGetter { private: static_assert(HasGetAtMethod>::value, "You must provide a get_at() static method for this vector_type"); - typedef decltype(&VectorWrapperInfo::get_at) get_at_func; + typedef typename VectorWrapperInfo::scalar_type scalar_type; + using get_at_func = decltype(&VectorWrapperInfo::get_at)(std::size_t, scalar_type&); static_assert(not std::is_rvalue_reference::type>::value, "rvalue ref return types not implemented"); static_assert(std::is_lvalue_reference::type>::value, "Read-only vectors not implemented"); @@ -261,7 +263,8 @@ namespace vwr { Vec ( void ) = default; Vec ( const Vec& ) = default; explicit Vec ( const vector_type& parIn ) : implem::VecBase(parIn) { } - explicit Vec ( const scalar_type parX ) : implem::VecBase(parX) { } + template + explicit Vec ( const typename std::enable_if::value and not std::is_same::value, T>::type& parX ) : implem::VecBase(parX) { } template Vec ( const Vec& parOther ) { implem::assign(*this, parOther); } scalar_type& x ( void ) { return (*this)[0]; } diff --git a/include/vectorwrapper/vectorwrapper.inl b/include/vectorwrapper/vectorwrapper.inl index 4b8deba..74c413f 100644 --- a/include/vectorwrapper/vectorwrapper.inl +++ b/include/vectorwrapper/vectorwrapper.inl @@ -17,7 +17,8 @@ namespace vwr { namespace implem { template - VecBase::VecBase (scalar_type parInit) : + template + VecBase::VecBase (const typename std::enable_if::value and not std::is_same::value, T>::type& parInit) : m_wrapped(parInit) { } @@ -121,7 +122,7 @@ namespace vwr { template typename VectorWrapperInfo::scalar_type& VecGetter::get_at (typename VectorWrapperInfo::vector_type& parVec, std::size_t parIndex) { assert(parIndex < VectorWrapperInfo::dimensions); - return VectorWrapperInfo::get_at(parVec, parIndex); + return VectorWrapperInfo::get_at(parIndex, parVec); } template