From 9ce9a7ce9996b46737f569b56923fdef26e783f6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 30 Jun 2020 21:58:58 +0300 Subject: [PATCH] Define protect(f)::result_type only when F::result_type is defined --- include/boost/bind/protect.hpp | 18 +++++++++++++++--- test/protect_test2.cpp | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/boost/bind/protect.hpp b/include/boost/bind/protect.hpp index d6a480d..e251129 100644 --- a/include/boost/bind/protect.hpp +++ b/include/boost/bind/protect.hpp @@ -24,7 +24,21 @@ namespace _bi #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE) -template class protected_bind_t +template struct protect_make_void +{ + typedef void type; +}; + +template struct protect_result_type +{ +}; + +template struct protect_result_type< F, typename protect_make_void::type > +{ + typedef typename F::result_type result_type; +}; + +template class protected_bind_t: public protect_result_type { private: @@ -32,8 +46,6 @@ private: public: - typedef typename F::result_type result_type; - explicit protected_bind_t( F f ): f_( f ) { } diff --git a/test/protect_test2.cpp b/test/protect_test2.cpp index 66bec47..0c29500 100644 --- a/test/protect_test2.cpp +++ b/test/protect_test2.cpp @@ -18,9 +18,29 @@ struct X struct result_type {}; }; +struct Y +{ +}; + +template struct inherit: T, U +{ +}; + +template void test2( F ) +{ + // test that F doesn't have ::result_type + BOOST_TEST_TRAIT_TRUE((boost::core::is_same::result_type, typename X::result_type>)); +} + int main() { test( boost::protect( X() ) ); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE) + + test2( boost::protect( Y() ) ); + +#endif + return boost::report_errors(); }