Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/bitcoin/system/boost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
// warnings are included by define.hpp which follows boost includes.
#include <bitcoin/system/warnings.hpp>

// Include boost only from here, so exception disable works.
// Include boost only from here, so this exclusion works.
// Avoid namespace conflict between boost::placeholders and std::placeholders.
// This arises when including <functional>, which declares std::placeholders.
// www.boost.org/doc/libs/1_78_0/boost/bind.hpp
// Include boost only from here, so placeholders exclusion works.
#define BOOST_BIND_NO_PLACEHOLDERS
#include <boost/bind.hpp>

#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/format.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/json.hpp>
Expand Down
7 changes: 7 additions & 0 deletions include/bitcoin/system/data/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
/// shared_ptr
/// ---------------------------------------------------------------------------

/// Create shared pointer to non-const from moved instance.
template <typename Type>
inline std::shared_ptr<Type> make_shared(Type&& value) NOEXCEPT
{
return std::make_shared<Type>(std::forward<Type>(value));
}

/// Create default shared pointer.
template <typename Type>
inline std::shared_ptr<Type> to_shared() NOEXCEPT
Expand Down
2 changes: 1 addition & 1 deletion src/define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#include <bitcoin/system/define.hpp>

// Required in source (cpp) I replaced for boost header only.
// Required in source (cpp) for boost header only.
#include <boost/json/src.hpp>

// This is a maintainer file to force rebuild of /system only.
Expand Down
20 changes: 16 additions & 4 deletions test/data/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ struct type
int right;
};

// make_shared

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

BOOST_AUTO_TEST_CASE(memory__make_shared__array_move__expected_values)
{
const test_array_shared_ptr ptr = make_shared<data_array<3>>(data_array<3>{ 1, 2, 3 });
BOOST_REQUIRE_EQUAL(ptr->at(0), 1);
BOOST_REQUIRE_EQUAL(ptr->at(1), 2);
BOOST_REQUIRE_EQUAL(ptr->at(2), 3);
}

// to_shared

using test_array_shared_ptr = std::shared_ptr<const data_array<3>>;
using test_const_array_shared_ptr = std::shared_ptr<const data_array<3>>;

BOOST_AUTO_TEST_CASE(memory__to_shared1__array_default__default_values)
{
const test_array_shared_ptr ptr = to_shared<data_array<3>>();
const test_const_array_shared_ptr ptr = to_shared<data_array<3>>();
BOOST_REQUIRE_EQUAL(ptr->at(0), 0);
BOOST_REQUIRE_EQUAL(ptr->at(1), 0);
BOOST_REQUIRE_EQUAL(ptr->at(2), 0);
Expand All @@ -46,15 +58,15 @@ BOOST_AUTO_TEST_CASE(memory__to_shared1__array_default__default_values)
BOOST_AUTO_TEST_CASE(memory__to_shared5__array_copy__expected_values)
{
const data_array<3> copy{ 1, 2, 3 };
const test_array_shared_ptr ptr = to_shared<data_array<3>>(copy);
const test_const_array_shared_ptr ptr = to_shared<data_array<3>>(copy);
BOOST_REQUIRE_EQUAL(ptr->at(0), 1);
BOOST_REQUIRE_EQUAL(ptr->at(1), 2);
BOOST_REQUIRE_EQUAL(ptr->at(2), 3);
}

BOOST_AUTO_TEST_CASE(memory__to_shared5__array_move__expected_values)
{
const test_array_shared_ptr ptr = to_shared<data_array<3>>(data_array<3>{ 1, 2, 3 });
const test_const_array_shared_ptr ptr = to_shared<data_array<3>>(data_array<3>{ 1, 2, 3 });
BOOST_REQUIRE_EQUAL(ptr->at(0), 1);
BOOST_REQUIRE_EQUAL(ptr->at(1), 2);
BOOST_REQUIRE_EQUAL(ptr->at(2), 3);
Expand Down
Loading