diff --git a/alloc/easy.hpp b/alloc/easy.hpp index 5e749111..868155fb 100644 --- a/alloc/easy.hpp +++ b/alloc/easy.hpp @@ -3,7 +3,7 @@ * 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 2018 Danny Robson + * Copyright 2018-2020, Danny Robson */ #pragma once @@ -11,9 +11,10 @@ #include "traits.hpp" +#include "../buffer/traits.hpp" +#include "../concepts.hpp" #include "../std.hpp" #include "../view.hpp" -#include "../buffer/traits.hpp" #include #include @@ -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::value_type; + + auto store = array (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