diff --git a/include/bitcoin/system/data/memory.hpp b/include/bitcoin/system/data/memory.hpp index 2a4ddc206c..0bb1585553 100644 --- a/include/bitcoin/system/data/memory.hpp +++ b/include/bitcoin/system/data/memory.hpp @@ -63,7 +63,7 @@ inline std::shared_ptr to_shared(const Type& value) NOEXCEPT } /// Construct shared pointer to const from moved constructor parameters. -template +template inline std::shared_ptr to_shared(Args&&... values) NOEXCEPT { return std::make_shared(Type{ std::forward(values)... }); @@ -79,6 +79,11 @@ template std::shared_ptr>> to_shareds(const std_vector& values) NOEXCEPT; +/// Allocate a shared instance and construct with given arguments. +template +std::shared_ptr to_allocated(const Allocator& allocator, + Args&&... args) NOEXCEPT; + /// unique_ptr /// --------------------------------------------------------------------------- @@ -97,7 +102,7 @@ inline std::unique_ptr to_unique(const Type& value) NOEXCEPT } /// Construct unique pointer to const from moved constructor parameters. -template +template inline std::unique_ptr to_unique(Args&&... values) NOEXCEPT { return std::make_unique(Type{ std::forward(values)... }); diff --git a/include/bitcoin/system/impl/data/memory.ipp b/include/bitcoin/system/impl/data/memory.ipp index 459694f57b..1aa99cf5a0 100644 --- a/include/bitcoin/system/impl/data/memory.ipp +++ b/include/bitcoin/system/impl/data/memory.ipp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -30,7 +31,7 @@ namespace system { BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) -/// Create shared pointer to vector of const shared ptr from the moved vector. +// Create shared pointer to vector of const shared ptr from the moved vector. template std::shared_ptr>> to_shareds(std_vector&& values) NOEXCEPT @@ -47,7 +48,7 @@ to_shareds(std_vector&& values) NOEXCEPT return out; } -/// Create shared pointer to vector of const shared ptr from the copied vector. +// Create shared pointer to vector of const shared ptr from the copied vector. template std::shared_ptr>> to_shareds( const std_vector& values) NOEXCEPT @@ -64,6 +65,16 @@ std::shared_ptr>> to_shareds( return out; } +// Allocate a shared instance and construct with given arguments. +template +std::shared_ptr to_allocated(const Allocator& allocator, + Args&&... args) NOEXCEPT +{ + return std::allocate_shared>(allocator, + std::forward(args)...); +} + BC_POP_WARNING() } // namespace system