From c2929ea6c66f69867aea8924c2fa679a9b6ba19e Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 4 Mar 2020 01:02:52 +0300 Subject: [PATCH] Updated to use boost/bind/bind.hpp to avoid warnings and compliance with C++20. boost/bind.hpp emits warnings about deprecating global placeholder argument keywords. C++20 removes std::bind1st/bind2nd, so replaced their usage with boost::bind. --- doc/quickbook/filter_iterator.qbk | 4 ++-- doc/quickbook/indirect_iterator.qbk | 2 +- example/filter_iterator_example.cpp | 5 +++-- example/indirect_iterator_example.cpp | 3 ++- test/transform_iterator_test.cpp | 29 +++++++++++++-------------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/doc/quickbook/filter_iterator.qbk b/doc/quickbook/filter_iterator.qbk index f212003..e7cace8 100644 --- a/doc/quickbook/filter_iterator.qbk +++ b/doc/quickbook/filter_iterator.qbk @@ -50,11 +50,11 @@ the integers greater than `-2`. // Another example using make_filter_iterator() std::copy( boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) + std::bind(std::greater(), std::placeholders::_1, -2) , numbers, numbers + N) , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) + std::bind(std::greater(), std::placeholders::_1, -2) , numbers + N, numbers + N) , std::ostream_iterator(std::cout, " ") diff --git a/doc/quickbook/indirect_iterator.qbk b/doc/quickbook/indirect_iterator.qbk index 06623f9..89ab38c 100644 --- a/doc/quickbook/indirect_iterator.qbk +++ b/doc/quickbook/indirect_iterator.qbk @@ -49,7 +49,7 @@ using the `make_indirect_iterator` helper function. const_indirect_last(pointers_to_chars + N); std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); + mutable_indirect_first, std::bind(std::plus(), 1, std::placeholders::_1)); std::copy(mutable_indirect_first, mutable_indirect_last, std::ostream_iterator(std::cout, ",")); diff --git a/example/filter_iterator_example.cpp b/example/filter_iterator_example.cpp index 8880c8d..610c29b 100644 --- a/example/filter_iterator_example.cpp +++ b/example/filter_iterator_example.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include // for exit_success struct is_positive_number { @@ -42,11 +43,11 @@ int main() // Another example using make_filter_iterator() std::copy( boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) + boost::bind(std::greater(), boost::placeholders::_1, -2) , numbers, numbers + N) , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) + boost::bind(std::greater(), boost::placeholders::_1, -2) , numbers + N, numbers + N) , std::ostream_iterator(std::cout, " ") diff --git a/example/indirect_iterator_example.cpp b/example/indirect_iterator_example.cpp index abbf46c..478f9bc 100644 --- a/example/indirect_iterator_example.cpp +++ b/example/indirect_iterator_example.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include int main(int, char*[]) @@ -41,7 +42,7 @@ int main(int, char*[]) const_indirect_last(pointers_to_chars + N); std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); + mutable_indirect_first, boost::bind(std::plus(), 1, boost::placeholders::_1)); std::copy(mutable_indirect_first, mutable_indirect_last, std::ostream_iterator(std::cout, ",")); diff --git a/test/transform_iterator_test.cpp b/test/transform_iterator_test.cpp index 3caad2a..7a77b2c 100644 --- a/test/transform_iterator_test.cpp +++ b/test/transform_iterator_test.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION @@ -114,9 +113,9 @@ struct polymorphic_mult_functor template struct result {typedef void type;}; template struct result {typedef void type;}; - template + template T operator()(const T& _arg) const {return _arg*2;} - template + template void operator()(const T& _arg) { BOOST_ASSERT(0); } }; @@ -139,15 +138,15 @@ main() for (int k = 0; k < N; ++k) x[k] = k; std::copy(x, x + N, y); - + for (int k2 = 0; k2 < N; ++k2) x[k2] = x[k2] * 2; - + typedef boost::transform_iterator iter_t; iter_t i(y, adaptable_mult_functor(2)); boost::input_iterator_test(i, x[0], x[1]); boost::input_iterator_test(iter_t(&y[0], adaptable_mult_functor(2)), x[0], x[1]); - + boost::random_access_readable_iterator_test(i, N, x); } @@ -157,15 +156,15 @@ main() for (int k = 0; k < N; ++k) x[k] = k; std::copy(x, x + N, y); - + for (int k2 = 0; k2 < N; ++k2) x[k2] = x[k2] * 2; - + typedef boost::transform_iterator iter_t; iter_t i(y, mult_functor(2)); boost::input_iterator_test(i, x[0], x[1]); boost::input_iterator_test(iter_t(&y[0], mult_functor(2)), x[0], x[1]); - + boost::random_access_readable_iterator_test(i, N, x); } @@ -196,16 +195,16 @@ main() for (int k = 0; k < N; ++k) x[k] = k; std::copy(x, x + N, y); - + for (int k2 = 0; k2 < N; ++k2) x[k2] = x[k2] * 2; - + boost::input_iterator_test( boost::make_transform_iterator(y, mult_2), x[0], x[1]); boost::input_iterator_test( boost::make_transform_iterator(&y[0], mult_2), x[0], x[1]); - + boost::random_access_readable_iterator_test( boost::make_transform_iterator(y, mult_2), N, x); @@ -267,16 +266,16 @@ main() for (int k = 0; k < N; ++k) x[k] = k; std::copy(x, x + N, y); - + for (int k2 = 0; k2 < N; ++k2) x[k2] = x[k2] * 2; - + boost::input_iterator_test( boost::make_transform_iterator(y, polymorphic_mult_functor()), x[0], x[1]); boost::input_iterator_test( boost::make_transform_iterator(&y[0], polymorphic_mult_functor()), x[0], x[1]); - + boost::random_access_readable_iterator_test( boost::make_transform_iterator(y, polymorphic_mult_functor()), N, x); }