2
0
mirror of https://github.com/boostorg/signals.git synced 2026-01-19 04:42:10 +00:00

Use unique_ptr instead of auto_ptr and bind instead bind1st where appropriate.

This commit is contained in:
Edward Diener
2016-11-07 02:16:15 -05:00
parent 16e522df2b
commit 9b99324340
3 changed files with 56 additions and 0 deletions

View File

@@ -72,8 +72,17 @@ namespace boost {
// Allocate storage for an iterator that will hold the point of
// insertion of the slot into the list. This is used to later remove
// the slot when it is disconnected.
#if defined(BOOST_NO_CXX11_SMART_PTR)
std::auto_ptr<iterator> saved_iter(new iterator);
#else
std::unique_ptr<iterator> saved_iter(new iterator);
#endif
// Add the slot to the list.
iterator pos =
slots_.insert(name, data->watch_bound_objects, slot_, at);
@@ -133,8 +142,17 @@ namespace boost {
signal_base_impl* self = reinterpret_cast<signal_base_impl*>(obj);
// We won't need the slot iterator after this
#if defined(BOOST_NO_CXX11_SMART_PTR)
std::auto_ptr<iterator> slot(reinterpret_cast<iterator*>(data));
#else
std::unique_ptr<iterator> slot(reinterpret_cast<iterator*>(data));
#endif
// If we're flags.clearing, we don't bother updating the list of slots
if (!self->flags.clearing) {
// If we're in a call, note the fact that a slot has been deleted so

View File

@@ -125,8 +125,17 @@ test_one_arg()
boost::signal1<int, int, max_or_default<int> > s1;
s1.connect(std::negate<int>());
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
s1.connect(std::bind1st(std::multiplies<int>(), 2));
#else
s1.connect(std::bind(std::multiplies<int>(), 2, std::placeholders::_1));
#endif
BOOST_CHECK(s1(1) == 2);
BOOST_CHECK(s1(-1) == 1);
}
@@ -143,9 +152,19 @@ test_signal_signal_connect()
{
boost::signal1<int, int, max_or_default<int> > s2;
s1.connect(s2);
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
s2.connect(std::bind1st(std::multiplies<int>(), 2));
s2.connect(std::bind1st(std::multiplies<int>(), -3));
#else
s2.connect(std::bind(std::multiplies<int>(), 2, std::placeholders::_1));
s2.connect(std::bind(std::multiplies<int>(), -3, std::placeholders::_1));
#endif
BOOST_CHECK(s2(-3) == 9);
BOOST_CHECK(s1(3) == 6);
} // s2 goes out of scope and disconnects

View File

@@ -123,8 +123,17 @@ test_one_arg()
boost::signal<int (int value), max_or_default<int> > s1;
s1.connect(std::negate<int>());
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
s1.connect(std::bind1st(std::multiplies<int>(), 2));
#else
s1.connect(std::bind(std::multiplies<int>(), 2, std::placeholders::_1));
#endif
BOOST_CHECK(s1(1) == 2);
BOOST_CHECK(s1(-1) == 1);
}
@@ -141,9 +150,19 @@ test_signal_signal_connect()
{
boost::signal<int (int value), max_or_default<int> > s2;
s1.connect(s2);
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
s2.connect(std::bind1st(std::multiplies<int>(), 2));
s2.connect(std::bind1st(std::multiplies<int>(), -3));
#else
s2.connect(std::bind(std::multiplies<int>(), 2, std::placeholders::_1));
s2.connect(std::bind(std::multiplies<int>(), -3, std::placeholders::_1));
#endif
BOOST_CHECK(s2(-3) == 9);
BOOST_CHECK(s1(3) == 6);
} // s2 goes out of scope and disconnects