implemented move for other with different capacity
This commit is contained in:
parent
297c42b176
commit
67d3a2f4cf
|
|
@ -57,6 +57,8 @@ namespace cc {
|
|||
template <std::size_t N2>
|
||||
constexpr const_vector(const const_vector<value_type, N2>& other);
|
||||
constexpr const_vector(const_vector&& other) noexcept;
|
||||
template <std::size_t N2>
|
||||
constexpr const_vector(const_vector<value_type, N2>&& other);
|
||||
|
||||
constexpr ~const_vector() = default; // elements in static array should be destroyed automatically
|
||||
|
||||
|
|
@ -64,6 +66,8 @@ namespace cc {
|
|||
template <std::size_t N2>
|
||||
constexpr const_vector<T, N>& operator=(const const_vector<value_type, N2>& other);
|
||||
constexpr const_vector<T, N>& operator=(const_vector&& other) noexcept;
|
||||
template <std::size_t N2>
|
||||
constexpr const_vector<T, N>& operator=(const_vector<value_type, N2>&& other);
|
||||
//constexpr const_vector<T, N>& operator=(const value_type (&array)[N]) noexcept; // not needed as functionally equivalent to templated overload
|
||||
template <std::size_t N2>
|
||||
constexpr const_vector<T, N>& operator=(const value_type (&array)[N2]) noexcept;
|
||||
|
|
@ -136,9 +140,8 @@ namespace cc {
|
|||
template<std::size_t N2>
|
||||
constexpr void swap(const_vector<T, N2>& other);
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
friend test_const_vector;
|
||||
#endif
|
||||
template <typename T2, std::size_t N2>
|
||||
friend class const_vector;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -253,6 +256,15 @@ namespace cc {
|
|||
std::move(other.begin(), other.end(), _arr);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
template<std::size_t N2>
|
||||
constexpr const_vector<T, N>::const_vector(const_vector<value_type, N2> &&other)
|
||||
: _size(other._size)
|
||||
{
|
||||
if (_len <= other.size()) throw std::invalid_argument("size of other has to be equal to or smaller than this");
|
||||
std::move(other.begin(), other.end(), _arr);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
constexpr const_vector<T, N> &const_vector<T, N>::operator=(const const_vector &other)
|
||||
{
|
||||
|
|
@ -292,6 +304,19 @@ namespace cc {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
template<std::size_t N2>
|
||||
constexpr const_vector<T, N> &const_vector<T, N>::operator=(const_vector<value_type, N2> &&other)
|
||||
{
|
||||
if (other.size() > _len) throw std::invalid_argument("size of other has to be equal to or smaller than this");
|
||||
|
||||
clear();
|
||||
std::move(other.begin(), other.end(), _arr);
|
||||
_size = other._size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
template<std::size_t N2>
|
||||
constexpr const_vector<T, N> &const_vector<T, N>::operator=(const value_type (&array)[N2]) noexcept
|
||||
|
|
|
|||
Loading…
Reference in New Issue