From a69ec062f1b6396f8609cc143391005191e1b307 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 27 Mar 2019 15:51:57 +1100 Subject: [PATCH] array/sarray: add move assignment operator --- array/sarray.hpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/array/sarray.hpp b/array/sarray.hpp index 561df291..24dd972c 100644 --- a/array/sarray.hpp +++ b/array/sarray.hpp @@ -3,13 +3,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2017 Danny Robson + * Copyright 2017-2019 Danny Robson */ #pragma once #include "../view.hpp" +#include "../iterator/zip.hpp" + #include #include @@ -67,6 +69,23 @@ namespace cruft { sarray (std::begin (_data), std::end (_data)) { ; } + + //--------------------------------------------------------------------- + sarray& operator= (sarray &&rhs) noexcept (std::is_nothrow_move_constructible_v) + { + // Destroy the currently held objects. + for (auto &obj: *this) + obj.~T (); + + // Move-construct the new objects + for (auto [idx, obj]: cruft::iterator::izip (rhs)) + new (&m_data.objects[idx]) T (std::move (obj)); + m_size = rhs.m_size; + + return *this; + } + + //--------------------------------------------------------------------- ~sarray () {