From c7b711550c53cdacb0964ef0dfed3df7b49a9b79 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 9 Mar 2021 12:14:17 +1000 Subject: [PATCH] map/multi_fixed: add assignment operators --- map/multi_fixed.hpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/map/multi_fixed.hpp b/map/multi_fixed.hpp index 1495251c..219f47cf 100644 --- a/map/multi_fixed.hpp +++ b/map/multi_fixed.hpp @@ -84,8 +84,31 @@ namespace cruft::map { } } - multi_fixed& operator= (multi_fixed&&) noexcept (std::is_nothrow_move_assignable_v) = default; - multi_fixed& operator= (multi_fixed const&) noexcept (std::is_nothrow_assignable_v) = default; + multi_fixed& + operator= (multi_fixed &&rhs) noexcept (std::is_nothrow_move_assignable_v) + { + for (std::size_t i = 0; i < m_size; ++i) + m_store.data[i].~value_type (); + m_size = 0; + + for (m_size = 0; m_size != rhs.m_size; ++m_size) + m_store.data[m_size] = std::move (rhs.m_store.data[m_size]); + + rhs.m_size = 0; + return *this; + } + + multi_fixed& + operator= (multi_fixed const &rhs) noexcept (std::is_nothrow_assignable_v) + { + for (std::size_t i = 0; i < m_size; ++i) + m_store.data[i].~value_type (); + + for (m_size = 0; m_size != rhs.m_size; ++m_size) + m_store.data[m_size] = rhs.m_store.data[m_size]; + + return *this; + } iterator begin (void)& { return m_store.data + 0; } iterator end (void)& { return m_store.data + m_size; }