Skip to content

Commit 6c5664a

Browse files
authored
Merge pull request #1748 from evoskuil/master
Rename make_shared to move_shared and add emplace_shared, test.
2 parents cc718ff + 9e09b96 commit 6c5664a

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

include/bitcoin/system/data/memory.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
3232

3333
/// shared_ptr
3434
/// ---------------------------------------------------------------------------
35+
/// Some of these are just used to suppress noexcept warnings.
3536

3637
/// Create shared pointer to non-const from moved instance.
3738
template <typename Type>
38-
inline std::shared_ptr<Type> make_shared(Type&& value) NOEXCEPT
39+
inline std::shared_ptr<Type> move_shared(Type&& value) NOEXCEPT
3940
{
4041
return std::make_shared<Type>(std::forward<Type>(value));
4142
}
4243

44+
/// Create shared pointer to an in-place constructed instance.
45+
template <typename Type, typename ...Args>
46+
inline std::shared_ptr<Type> emplace_shared(Args&&... args) NOEXCEPT
47+
{
48+
return std::make_shared<Type>(std::forward<Args>(args)...);
49+
}
50+
4351
/// Create default shared pointer.
4452
template <typename Type>
4553
inline std::shared_ptr<Type> to_shared() NOEXCEPT

test/data/memory.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,26 @@ struct type
3131
int right;
3232
};
3333

34+
// emplace_shared
35+
36+
using test_string_shared_ptr = std::shared_ptr<std::string>;
37+
38+
BOOST_AUTO_TEST_CASE(memory__emplace_shared__array_move__expected_values)
39+
{
40+
const test_string_shared_ptr ptr = system::emplace_shared<std::string>("test");
41+
}
42+
3443
// make_shared
3544

3645
using test_array_shared_ptr = std::shared_ptr<data_array<3>>;
3746

3847
BOOST_AUTO_TEST_CASE(memory__make_shared__array_move__expected_values)
3948
{
40-
const test_array_shared_ptr ptr = make_shared<data_array<3>>(data_array<3>{ 1, 2, 3 });
49+
const test_array_shared_ptr ptr = system::move_shared<data_array<3>>(data_array<3>{ 1, 2, 3 });
4150
BOOST_REQUIRE_EQUAL(ptr->at(0), 1);
4251
BOOST_REQUIRE_EQUAL(ptr->at(1), 2);
4352
BOOST_REQUIRE_EQUAL(ptr->at(2), 3);
44-
}
53+
}
4554

4655
// to_shared
4756

0 commit comments

Comments
 (0)