Fix copy-construction warning in clang

This bumps the c++ requirement to c++17
This commit is contained in:
King_DuckZ 2021-04-08 15:01:42 +02:00
parent 2c1bf17c6b
commit fcaa62d69f
6 changed files with 56 additions and 20 deletions

View file

@ -28,6 +28,7 @@ target_include_directories(${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(DIRECTORY include/vectorwrapper
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}

View file

@ -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>
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 );
public:
typedef V vector_type;
typedef typename VecBaseStorage<V>::vector_type vector_type;
typedef typename VectorWrapperInfo<V>::scalar_type scalar_type;
using VecBaseStorage<V>::data;
enum {
dimensions = VectorWrapperInfo<V>::dimensions
@ -70,6 +98,7 @@ namespace vwr {
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 vector_type& parInit );
VecBase ( const VecBase& parOther );
template <typename... Args>
VecBase ( scalar_type parX, scalar_type parY, Args... parArgs );
~VecBase ( void ) = default;
@ -77,9 +106,6 @@ namespace vwr {
scalar_type& operator[] ( size_type parIndex );
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 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);
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);
vector_type m_wrapped;
};
template <

View file

@ -28,22 +28,27 @@ namespace vwr {
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) {
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>
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... Args>
VecBase<V>::VecBase (scalar_type parX, scalar_type parY, Args... parArgs) {
static_assert(2 + sizeof...(Args) == dimensions, "Wrong number of parameters received");
VecGetter<V>::get_at(m_wrapped, 0) = parX;
VecGetter<V>::get_at(m_wrapped, 1) = parY;
VecGetter<V>::get_at(data(), 0) = parX;
VecGetter<V>::get_at(data(), 1) = parY;
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");
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);
}
@ -73,12 +78,12 @@ namespace vwr {
template <typename V>
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>
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>
@ -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);
return *this;
}
template <typename V>
inline VecBase<V>::VecBase (const VecBase& parOther) :
VecBase<V>(parOther.data())
{
}
} //namespace implem
} //namespace vwr

View file

@ -252,7 +252,7 @@ namespace vwr {
static const Vec<V, 1> unit_x;
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) { }
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) { }
@ -280,7 +280,7 @@ namespace vwr {
static const Vec<V, 2> unit_y;
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) { }
explicit Vec ( const scalar_type parX ) : implem::VecBase<V>(parX) { }
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;
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) { }
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) { }
@ -341,7 +341,7 @@ namespace vwr {
static const Vec<V, 4> unit_w;
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) { }
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) { }

View file

@ -65,7 +65,7 @@ namespace vwr {
template <typename V>
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;
}

View file

@ -1,7 +1,7 @@
project('vectorwrapper', 'cpp',
version: '1.1.2',
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')