array/sarray: add move assignment operator
This commit is contained in:
parent
9b994b12ae
commit
a69ec062f1
@ -3,13 +3,15 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*
|
*
|
||||||
* Copyright 2017 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2017-2019 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../view.hpp"
|
#include "../view.hpp"
|
||||||
|
|
||||||
|
#include "../iterator/zip.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@ -67,6 +69,23 @@ namespace cruft {
|
|||||||
sarray (std::begin (_data), std::end (_data))
|
sarray (std::begin (_data), std::end (_data))
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
sarray& operator= (sarray &&rhs) noexcept (std::is_nothrow_move_constructible_v<T>)
|
||||||
|
{
|
||||||
|
// 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 ()
|
~sarray ()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user