Fix copy-construction warning in clang
This bumps the c++ requirement to c++17
This commit is contained in:
parent
2c1bf17c6b
commit
fcaa62d69f
6 changed files with 56 additions and 20 deletions
|
@ -28,6 +28,7 @@ target_include_directories(${PROJECT_NAME}
|
||||||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
||||||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
)
|
)
|
||||||
|
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
|
||||||
|
|
||||||
install(DIRECTORY include/vectorwrapper
|
install(DIRECTORY include/vectorwrapper
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
|
|
@ -55,12 +55,40 @@ namespace vwr {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename V, bool IsCopyConstr=std::is_copy_constructible<V>::value>
|
||||||
|
class VecBaseStorage {
|
||||||
|
protected:
|
||||||
|
constexpr static const bool IsWrappedCopyConstructible = IsCopyConstr;
|
||||||
|
typedef V vector_type;
|
||||||
|
VecBaseStorage() = default;
|
||||||
|
VecBaseStorage (const VecBaseStorage& parOther) = delete;
|
||||||
|
VecBaseStorage (const vector_type& parInit) : m_wrapped(parInit) {}
|
||||||
|
vector_type& data ( void ) { return m_wrapped; }
|
||||||
|
const vector_type& data ( void ) const { return m_wrapped; }
|
||||||
|
private:
|
||||||
|
vector_type m_wrapped;
|
||||||
|
};
|
||||||
template <typename V>
|
template <typename V>
|
||||||
class VecBase {
|
class VecBaseStorage<V, false> {
|
||||||
|
protected:
|
||||||
|
constexpr static const bool IsWrappedCopyConstructible = false;
|
||||||
|
typedef V vector_type;
|
||||||
|
VecBaseStorage() = default;
|
||||||
|
VecBaseStorage (const VecBaseStorage&) = delete;
|
||||||
|
VecBaseStorage (const vector_type&) { }
|
||||||
|
vector_type& data ( void ) { return m_wrapped; }
|
||||||
|
const vector_type& data ( void ) const { return m_wrapped; }
|
||||||
|
private:
|
||||||
|
vector_type m_wrapped;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
class VecBase : private VecBaseStorage<V> {
|
||||||
friend Vec<V>& assign_same_type<V> ( Vec<V>& parLeft, const Vec<V>& parRight );
|
friend Vec<V>& assign_same_type<V> ( Vec<V>& parLeft, const Vec<V>& parRight );
|
||||||
public:
|
public:
|
||||||
typedef V vector_type;
|
typedef typename VecBaseStorage<V>::vector_type vector_type;
|
||||||
typedef typename VectorWrapperInfo<V>::scalar_type scalar_type;
|
typedef typename VectorWrapperInfo<V>::scalar_type scalar_type;
|
||||||
|
using VecBaseStorage<V>::data;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
dimensions = VectorWrapperInfo<V>::dimensions
|
dimensions = VectorWrapperInfo<V>::dimensions
|
||||||
|
@ -70,6 +98,7 @@ namespace vwr {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
explicit VecBase ( const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type=false );
|
explicit VecBase ( const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type=false );
|
||||||
explicit VecBase ( const vector_type& parInit );
|
explicit VecBase ( const vector_type& parInit );
|
||||||
|
VecBase ( const VecBase& parOther );
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
VecBase ( scalar_type parX, scalar_type parY, Args... parArgs );
|
VecBase ( scalar_type parX, scalar_type parY, Args... parArgs );
|
||||||
~VecBase ( void ) = default;
|
~VecBase ( void ) = default;
|
||||||
|
@ -77,9 +106,6 @@ namespace vwr {
|
||||||
scalar_type& operator[] ( size_type parIndex );
|
scalar_type& operator[] ( size_type parIndex );
|
||||||
const scalar_type& operator[] ( size_type parIndex ) const;
|
const scalar_type& operator[] ( size_type parIndex ) const;
|
||||||
|
|
||||||
vector_type& data ( void ) { return m_wrapped; }
|
|
||||||
const vector_type& data ( void ) const { return m_wrapped; }
|
|
||||||
|
|
||||||
operator vector_type&() {return this->data();}
|
operator vector_type&() {return this->data();}
|
||||||
operator const vector_type&() const {return this->data();}
|
operator const vector_type&() const {return this->data();}
|
||||||
|
|
||||||
|
@ -109,8 +135,6 @@ namespace vwr {
|
||||||
void assign_values_op (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const VecBase<V2>& parOther);
|
void assign_values_op (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const VecBase<V2>& parOther);
|
||||||
template <typename Op, size_type... I>
|
template <typename Op, size_type... I>
|
||||||
void assign_values_op_scalar (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const scalar_type& parOther);
|
void assign_values_op_scalar (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const scalar_type& parOther);
|
||||||
|
|
||||||
vector_type m_wrapped;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <
|
template <
|
||||||
|
|
|
@ -28,22 +28,27 @@ namespace vwr {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
VecBase<V>::VecBase (const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type) {
|
VecBase<V>::VecBase (const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type) {
|
||||||
for (size_type z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
for (size_type z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
||||||
VecGetter<V>::get_at(m_wrapped, z) = parInit;
|
VecGetter<V>::get_at(data(), z) = parInit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
VecBase<V>::VecBase (const vector_type& parInit) :
|
VecBase<V>::VecBase (const vector_type& parInit) :
|
||||||
m_wrapped(parInit)
|
VecBaseStorage<V>(parInit)
|
||||||
{
|
{
|
||||||
|
if constexpr (not VecBaseStorage<V>::IsWrappedCopyConstructible) {
|
||||||
|
for (size_type z = 0; z < dimensions; ++z) {
|
||||||
|
(*this)[z] = parInit[z];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
VecBase<V>::VecBase (scalar_type parX, scalar_type parY, Args... parArgs) {
|
VecBase<V>::VecBase (scalar_type parX, scalar_type parY, Args... parArgs) {
|
||||||
static_assert(2 + sizeof...(Args) == dimensions, "Wrong number of parameters received");
|
static_assert(2 + sizeof...(Args) == dimensions, "Wrong number of parameters received");
|
||||||
VecGetter<V>::get_at(m_wrapped, 0) = parX;
|
VecGetter<V>::get_at(data(), 0) = parX;
|
||||||
VecGetter<V>::get_at(m_wrapped, 1) = parY;
|
VecGetter<V>::get_at(data(), 1) = parY;
|
||||||
|
|
||||||
assign_values(bt::number_range<size_type, 2, dimensions>(), std::forward<Args>(parArgs)...);
|
assign_values(bt::number_range<size_type, 2, dimensions>(), std::forward<Args>(parArgs)...);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +59,7 @@ namespace vwr {
|
||||||
static_assert(sizeof...(I) == sizeof...(Args), "Argument count and indices count mismatch");
|
static_assert(sizeof...(I) == sizeof...(Args), "Argument count and indices count mismatch");
|
||||||
|
|
||||||
std::initializer_list<scalar_type> t {
|
std::initializer_list<scalar_type> t {
|
||||||
(VecGetter<V>::get_at(m_wrapped, I) = parArgs)...
|
(VecGetter<V>::get_at(data(), I) = parArgs)...
|
||||||
};
|
};
|
||||||
static_cast<void>(t);
|
static_cast<void>(t);
|
||||||
}
|
}
|
||||||
|
@ -73,12 +78,12 @@ namespace vwr {
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
auto VecBase<V>::operator[] (size_type parIndex) -> scalar_type& {
|
auto VecBase<V>::operator[] (size_type parIndex) -> scalar_type& {
|
||||||
return VecGetter<V>::get_at(m_wrapped, parIndex);
|
return VecGetter<V>::get_at(data(), parIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
auto VecBase<V>::operator[] (size_type parIndex) const -> const scalar_type& {
|
auto VecBase<V>::operator[] (size_type parIndex) const -> const scalar_type& {
|
||||||
return VecGetter<V>::get_at(const_cast<vector_type&>(m_wrapped), parIndex);
|
return VecGetter<V>::get_at(const_cast<vector_type&>(data()), parIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
|
@ -181,6 +186,12 @@ namespace vwr {
|
||||||
this->assign_values_op_scalar(std::divides<scalar_type>(), bt::number_range<size_type, 0, VectorWrapperInfo<V>::dimensions>(), parOther);
|
this->assign_values_op_scalar(std::divides<scalar_type>(), bt::number_range<size_type, 0, VectorWrapperInfo<V>::dimensions>(), parOther);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
inline VecBase<V>::VecBase (const VecBase& parOther) :
|
||||||
|
VecBase<V>(parOther.data())
|
||||||
|
{
|
||||||
|
}
|
||||||
} //namespace implem
|
} //namespace implem
|
||||||
} //namespace vwr
|
} //namespace vwr
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace vwr {
|
||||||
static const Vec<V, 1> unit_x;
|
static const Vec<V, 1> unit_x;
|
||||||
|
|
||||||
Vec ( void ) = default;
|
Vec ( void ) = default;
|
||||||
Vec ( const Vec& parOther ) { implem::assign_same_type(*this, parOther); }
|
Vec ( const Vec& parOther ) : implem::VecBase<V>(parOther) { }
|
||||||
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
explicit Vec ( const typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, T>::type& parX ) : implem::VecBase<V>(parX) { }
|
explicit Vec ( const typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, T>::type& parX ) : implem::VecBase<V>(parX) { }
|
||||||
|
@ -280,7 +280,7 @@ namespace vwr {
|
||||||
static const Vec<V, 2> unit_y;
|
static const Vec<V, 2> unit_y;
|
||||||
|
|
||||||
Vec ( void ) = default;
|
Vec ( void ) = default;
|
||||||
Vec ( const Vec& parOther ) { implem::assign_same_type(*this, parOther); }
|
Vec ( const Vec& parOther ) : implem::VecBase<V>(parOther) { }
|
||||||
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
||||||
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
||||||
Vec ( scalar_type parX, scalar_type parY ) : implem::VecBase<V>(parX, parY) { }
|
Vec ( scalar_type parX, scalar_type parY ) : implem::VecBase<V>(parX, parY) { }
|
||||||
|
@ -310,7 +310,7 @@ namespace vwr {
|
||||||
static const Vec<V, 3> unit_z;
|
static const Vec<V, 3> unit_z;
|
||||||
|
|
||||||
Vec ( void ) = default;
|
Vec ( void ) = default;
|
||||||
Vec ( const Vec& parOther ) { implem::assign_same_type(*this, parOther); }
|
Vec ( const Vec& parOther ) : implem::VecBase<V>(parOther) { }
|
||||||
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
||||||
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
||||||
Vec ( scalar_type parX, scalar_type parY, scalar_type parZ ) : implem::VecBase<V>(parX, parY, parZ) { }
|
Vec ( scalar_type parX, scalar_type parY, scalar_type parZ ) : implem::VecBase<V>(parX, parY, parZ) { }
|
||||||
|
@ -341,7 +341,7 @@ namespace vwr {
|
||||||
static const Vec<V, 4> unit_w;
|
static const Vec<V, 4> unit_w;
|
||||||
|
|
||||||
Vec ( void ) = default;
|
Vec ( void ) = default;
|
||||||
Vec ( const Vec& parOther ) { implem::assign_same_type(*this, parOther); }
|
Vec ( const Vec& parOther ) : implem::VecBase<V>(parOther) { }
|
||||||
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
Vec ( const vector_type& parIn ) : implem::VecBase<V>(parIn) { }
|
||||||
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
|
||||||
Vec ( scalar_type parX, scalar_type parY, scalar_type parZ, scalar_type parW ) : implem::VecBase<V>(parX, parY, parZ, parW) { }
|
Vec ( scalar_type parX, scalar_type parY, scalar_type parZ, scalar_type parW ) : implem::VecBase<V>(parX, parY, parZ, parW) { }
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace vwr {
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
Vec<V>& assign_same_type (Vec<V>& parLeft, const Vec<V>& parRight) {
|
Vec<V>& assign_same_type (Vec<V>& parLeft, const Vec<V>& parRight) {
|
||||||
implem::AssignWrapped<V>::assign(parLeft.m_wrapped, parRight.m_wrapped);
|
implem::AssignWrapped<V>::assign(parLeft.data(), parRight.data());
|
||||||
return parLeft;
|
return parLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
project('vectorwrapper', 'cpp',
|
project('vectorwrapper', 'cpp',
|
||||||
version: '1.1.2',
|
version: '1.1.2',
|
||||||
meson_version: '>=0.50.0',
|
meson_version: '>=0.50.0',
|
||||||
default_options:['cpp_std=c++11', 'b_ndebug=if-release']
|
default_options:['cpp_std=c++17', 'b_ndebug=if-release']
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg = import('pkgconfig')
|
pkg = import('pkgconfig')
|
||||||
|
|
Loading…
Reference in a new issue