From 67d3a2f4cf569c7be47b17612c0f59342f958a1d Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 22 Jul 2024 22:51:22 +0200 Subject: [PATCH] implemented move for other with different capacity --- include/const_vector.hpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/include/const_vector.hpp b/include/const_vector.hpp index 7bfbef8..b089aa4 100644 --- a/include/const_vector.hpp +++ b/include/const_vector.hpp @@ -57,6 +57,8 @@ namespace cc { template constexpr const_vector(const const_vector& other); constexpr const_vector(const_vector&& other) noexcept; + template + constexpr const_vector(const_vector&& other); constexpr ~const_vector() = default; // elements in static array should be destroyed automatically @@ -64,6 +66,8 @@ namespace cc { template constexpr const_vector& operator=(const const_vector& other); constexpr const_vector& operator=(const_vector&& other) noexcept; + template + constexpr const_vector& operator=(const_vector&& other); //constexpr const_vector& operator=(const value_type (&array)[N]) noexcept; // not needed as functionally equivalent to templated overload template constexpr const_vector& operator=(const value_type (&array)[N2]) noexcept; @@ -136,9 +140,8 @@ namespace cc { template constexpr void swap(const_vector& other); -#ifdef UNIT_TEST - friend test_const_vector; -#endif + template + friend class const_vector; }; @@ -253,6 +256,15 @@ namespace cc { std::move(other.begin(), other.end(), _arr); } + template + template + constexpr const_vector::const_vector(const_vector &&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 constexpr const_vector &const_vector::operator=(const const_vector &other) { @@ -292,6 +304,19 @@ namespace cc { return *this; } + template + template + constexpr const_vector &const_vector::operator=(const_vector &&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 template constexpr const_vector &const_vector::operator=(const value_type (&array)[N2]) noexcept