From f50f42aae9a47299231f42a0c7bbc8d8a958159c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 27 Aug 2020 20:19:32 +0300 Subject: [PATCH] Enable the type<> syntax for noexcept member functions; add test; closes #23 --- include/boost/bind/bind.hpp | 1 + include/boost/bind/bind_mf2_cc.hpp | 36 +++---- test/Jamfile.v2 | 1 + test/bind_noexcept_mf2_test.cpp | 154 +++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+), 18 deletions(-) create mode 100644 test/bind_noexcept_mf2_test.cpp diff --git a/include/boost/bind/bind.hpp b/include/boost/bind/bind.hpp index a6f3447..2301234 100644 --- a/include/boost/bind/bind.hpp +++ b/include/boost/bind/bind.hpp @@ -2169,6 +2169,7 @@ template +# include # endif #undef BOOST_BIND_MF_NAME diff --git a/include/boost/bind/bind_mf2_cc.hpp b/include/boost/bind/bind_mf2_cc.hpp index 66476bc..be20b1d 100644 --- a/include/boost/bind/bind_mf2_cc.hpp +++ b/include/boost/bind/bind_mf2_cc.hpp @@ -18,7 +18,7 @@ template _bi::bind_t, typename _bi::list_av_1::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (), A1 a1) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) () BOOST_BIND_MF_NOEXCEPT, A1 a1) { typedef _mfi::BOOST_BIND_MF_NAME(mf0) F; typedef typename _bi::list_av_1::type list_type; @@ -28,7 +28,7 @@ template _bi::bind_t, typename _bi::list_av_1::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) () const, A1 a1) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) () const BOOST_BIND_MF_NOEXCEPT, A1 a1) { typedef _mfi::BOOST_BIND_MF_NAME(cmf0) F; typedef typename _bi::list_av_1::type list_type; @@ -41,7 +41,7 @@ template _bi::bind_t, typename _bi::list_av_2::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1), A1 a1, A2 a2) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2) { typedef _mfi::BOOST_BIND_MF_NAME(mf1) F; typedef typename _bi::list_av_2::type list_type; @@ -52,7 +52,7 @@ template _bi::bind_t, typename _bi::list_av_2::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1) const, A1 a1, A2 a2) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2) { typedef _mfi::BOOST_BIND_MF_NAME(cmf1) F; typedef typename _bi::list_av_2::type list_type; @@ -65,7 +65,7 @@ template _bi::bind_t, typename _bi::list_av_3::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2), A1 a1, A2 a2, A3 a3) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3) { typedef _mfi::BOOST_BIND_MF_NAME(mf2) F; typedef typename _bi::list_av_3::type list_type; @@ -76,7 +76,7 @@ template _bi::bind_t, typename _bi::list_av_3::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2) const, A1 a1, A2 a2, A3 a3) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3) { typedef _mfi::BOOST_BIND_MF_NAME(cmf2) F; typedef typename _bi::list_av_3::type list_type; @@ -89,7 +89,7 @@ template _bi::bind_t, typename _bi::list_av_4::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3), A1 a1, A2 a2, A3 a3, A4 a4) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4) { typedef _mfi::BOOST_BIND_MF_NAME(mf3) F; typedef typename _bi::list_av_4::type list_type; @@ -100,7 +100,7 @@ template _bi::bind_t, typename _bi::list_av_4::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3) const, A1 a1, A2 a2, A3 a3, A4 a4) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4) { typedef _mfi::BOOST_BIND_MF_NAME(cmf3) F; typedef typename _bi::list_av_4::type list_type; @@ -113,7 +113,7 @@ template _bi::bind_t, typename _bi::list_av_5::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { typedef _mfi::BOOST_BIND_MF_NAME(mf4) F; typedef typename _bi::list_av_5::type list_type; @@ -124,7 +124,7 @@ template _bi::bind_t, typename _bi::list_av_5::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { typedef _mfi::BOOST_BIND_MF_NAME(cmf4) F; typedef typename _bi::list_av_5::type list_type; @@ -137,7 +137,7 @@ template _bi::bind_t, typename _bi::list_av_6::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { typedef _mfi::BOOST_BIND_MF_NAME(mf5) F; typedef typename _bi::list_av_6::type list_type; @@ -148,7 +148,7 @@ template _bi::bind_t, typename _bi::list_av_6::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { typedef _mfi::BOOST_BIND_MF_NAME(cmf5) F; typedef typename _bi::list_av_6::type list_type; @@ -161,7 +161,7 @@ template _bi::bind_t, typename _bi::list_av_7::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { typedef _mfi::BOOST_BIND_MF_NAME(mf6) F; typedef typename _bi::list_av_7::type list_type; @@ -172,7 +172,7 @@ template _bi::bind_t, typename _bi::list_av_7::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { typedef _mfi::BOOST_BIND_MF_NAME(cmf6) F; typedef typename _bi::list_av_7::type list_type; @@ -185,7 +185,7 @@ template _bi::bind_t, typename _bi::list_av_8::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { typedef _mfi::BOOST_BIND_MF_NAME(mf7) F; typedef typename _bi::list_av_8::type list_type; @@ -196,7 +196,7 @@ template _bi::bind_t, typename _bi::list_av_8::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { typedef _mfi::BOOST_BIND_MF_NAME(cmf7) F; typedef typename _bi::list_av_8::type list_type; @@ -209,7 +209,7 @@ template _bi::bind_t, typename _bi::list_av_9::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8) BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { typedef _mfi::BOOST_BIND_MF_NAME(mf8) F; typedef typename _bi::list_av_9::type list_type; @@ -220,7 +220,7 @@ template _bi::bind_t, typename _bi::list_av_9::type> - BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8) const, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) + BOOST_BIND(boost::type, R (BOOST_BIND_MF_CC T::*f) (B1, B2, B3, B4, B5, B6, B7, B8) const BOOST_BIND_MF_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { typedef _mfi::BOOST_BIND_MF_NAME(cmf8) F; typedef typename _bi::list_av_9::type list_type; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 828dfdb..0974fca 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -77,3 +77,4 @@ run mem_fn_noexcept_test.cpp ; run bind_cpp20_test.cpp ; run protect_test2.cpp ; run protect_cpp20_test.cpp ; +run bind_noexcept_mf2_test.cpp ; diff --git a/test/bind_noexcept_mf2_test.cpp b/test/bind_noexcept_mf2_test.cpp new file mode 100644 index 0000000..369f384 --- /dev/null +++ b/test/bind_noexcept_mf2_test.cpp @@ -0,0 +1,154 @@ +// +// bind_noexcept_mf2_test.cpp - noexcept member functions w/ the type<> syntax +// +// Copyright 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include +#include +#include + +#if defined(BOOST_NO_CXX11_NOEXCEPT) + +int main() +{ +} + +#else + +// + +struct X +{ + mutable unsigned int hash; + + X(): hash(0) {} + + int f0() noexcept { f1(17); return 0; } + int g0() const noexcept { g1(17); return 0; } + + int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; } + int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } + + int f2(int a1, int a2) noexcept { f1(a1); f1(a2); return 0; } + int g2(int a1, int a2) const noexcept { g1(a1); g1(a2); return 0; } + + int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a3); return 0; } + int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a3); return 0; } + + int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a4); return 0; } + int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a4); return 0; } + + int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a5); return 0; } + int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a5); return 0; } + + int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { f5(a1, a2, a3, a4, a5); f1(a6); return 0; } + int g6(int a1, int a2, int a3, int a4, int a5, int a6) const noexcept { g5(a1, a2, a3, a4, a5); g1(a6); return 0; } + + int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) noexcept { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; } + int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const noexcept { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; } + + int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) noexcept { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; } + int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const noexcept { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; } +}; + +void member_function_test() +{ + X x; + + // 0 + + boost::bind(boost::type(), &X::f0, &x)(); + boost::bind(boost::type(), &X::f0, boost::ref(x))(); + + boost::bind(boost::type(), &X::g0, &x)(); + boost::bind(boost::type(), &X::g0, x)(); + boost::bind(boost::type(), &X::g0, boost::ref(x))(); + + // 1 + + boost::bind(boost::type(), &X::f1, &x, 1)(); + boost::bind(boost::type(), &X::f1, boost::ref(x), 1)(); + + boost::bind(boost::type(), &X::g1, &x, 1)(); + boost::bind(boost::type(), &X::g1, x, 1)(); + boost::bind(boost::type(), &X::g1, boost::ref(x), 1)(); + + // 2 + + boost::bind(boost::type(), &X::f2, &x, 1, 2)(); + boost::bind(boost::type(), &X::f2, boost::ref(x), 1, 2)(); + + boost::bind(boost::type(), &X::g2, &x, 1, 2)(); + boost::bind(boost::type(), &X::g2, x, 1, 2)(); + boost::bind(boost::type(), &X::g2, boost::ref(x), 1, 2)(); + + // 3 + + boost::bind(boost::type(), &X::f3, &x, 1, 2, 3)(); + boost::bind(boost::type(), &X::f3, boost::ref(x), 1, 2, 3)(); + + boost::bind(boost::type(), &X::g3, &x, 1, 2, 3)(); + boost::bind(boost::type(), &X::g3, x, 1, 2, 3)(); + boost::bind(boost::type(), &X::g3, boost::ref(x), 1, 2, 3)(); + + // 4 + + boost::bind(boost::type(), &X::f4, &x, 1, 2, 3, 4)(); + boost::bind(boost::type(), &X::f4, boost::ref(x), 1, 2, 3, 4)(); + + boost::bind(boost::type(), &X::g4, &x, 1, 2, 3, 4)(); + boost::bind(boost::type(), &X::g4, x, 1, 2, 3, 4)(); + boost::bind(boost::type(), &X::g4, boost::ref(x), 1, 2, 3, 4)(); + + // 5 + + boost::bind(boost::type(), &X::f5, &x, 1, 2, 3, 4, 5)(); + boost::bind(boost::type(), &X::f5, boost::ref(x), 1, 2, 3, 4, 5)(); + + boost::bind(boost::type(), &X::g5, &x, 1, 2, 3, 4, 5)(); + boost::bind(boost::type(), &X::g5, x, 1, 2, 3, 4, 5)(); + boost::bind(boost::type(), &X::g5, boost::ref(x), 1, 2, 3, 4, 5)(); + + // 6 + + boost::bind(boost::type(), &X::f6, &x, 1, 2, 3, 4, 5, 6)(); + boost::bind(boost::type(), &X::f6, boost::ref(x), 1, 2, 3, 4, 5, 6)(); + + boost::bind(boost::type(), &X::g6, &x, 1, 2, 3, 4, 5, 6)(); + boost::bind(boost::type(), &X::g6, x, 1, 2, 3, 4, 5, 6)(); + boost::bind(boost::type(), &X::g6, boost::ref(x), 1, 2, 3, 4, 5, 6)(); + + // 7 + + boost::bind(boost::type(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)(); + boost::bind(boost::type(), &X::f7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)(); + + boost::bind(boost::type(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)(); + boost::bind(boost::type(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)(); + boost::bind(boost::type(), &X::g7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)(); + + // 8 + + boost::bind(boost::type(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); + boost::bind(boost::type(), &X::f8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)(); + + boost::bind(boost::type(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); + boost::bind(boost::type(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)(); + boost::bind(boost::type(), &X::g8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)(); + + BOOST_TEST( x.hash == 23558 ); +} + +int main() +{ + member_function_test(); + return boost::report_errors(); +} + +#endif