alloc/easy: add move initialisation for array allocations
This commit is contained in:
parent
2aafaeb119
commit
272e8f286a
@ -3,7 +3,7 @@
|
|||||||
* 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 2018 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2018-2020, Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -11,9 +11,10 @@
|
|||||||
|
|
||||||
#include "traits.hpp"
|
#include "traits.hpp"
|
||||||
|
|
||||||
|
#include "../buffer/traits.hpp"
|
||||||
|
#include "../concepts.hpp"
|
||||||
#include "../std.hpp"
|
#include "../std.hpp"
|
||||||
#include "../view.hpp"
|
#include "../view.hpp"
|
||||||
#include "../buffer/traits.hpp"
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -159,6 +160,26 @@ namespace cruft::alloc::easy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Allocates storage for an array of ValueT, moves the values from
|
||||||
|
/// ContainerT into this storage, and returns a view over the memory.
|
||||||
|
template <
|
||||||
|
concepts::iterable ContainerT
|
||||||
|
>
|
||||||
|
auto
|
||||||
|
array (ContainerT &&container)
|
||||||
|
{
|
||||||
|
using IteratorT = decltype (std::begin (container));
|
||||||
|
using ValueT = typename std::iterator_traits<IteratorT>::value_type;
|
||||||
|
|
||||||
|
auto store = array<ValueT> (std::size (container));
|
||||||
|
std::copy (
|
||||||
|
std::move_iterator (std::begin (container)),
|
||||||
|
std::move_iterator (std::end (container)),
|
||||||
|
std::begin (store)
|
||||||
|
);
|
||||||
|
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Create an object of type `U` using `acquire` and wrap the result
|
/// Create an object of type `U` using `acquire` and wrap the result
|
||||||
|
Loading…
Reference in New Issue
Block a user