1// protect_test2.cpp
2//
3// Copyright 2020 Peter Dimov
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#include <boost/bind/protect.hpp>
8#include <boost/core/lightweight_test_trait.hpp>
9#include <boost/config.hpp>
10
11#if defined(BOOST_MSVC)
12# pragma warning( disable: 4510 ) // default constructor could not be generated
13# pragma warning( disable: 4610 ) // class can never be instantiated - constructor required
14#endif
15
16template<class T, class F> void test( F )
17{
18 BOOST_TEST_TRAIT_SAME(typename T::result_type, typename F::result_type);
19}
20
21struct X
22{
23 struct result_type {};
24};
25
26struct Y
27{
28};
29
30template<class T, class U> struct inherit: T, U
31{
32};
33
34template<class F> void test2( F )
35{
36 // test that F doesn't have ::result_type
37 BOOST_TEST_TRAIT_SAME(typename inherit<F, X>::result_type, typename X::result_type);
38}
39
40int main()
41{
42 test<X>( boost::protect( f: X() ) );
43
44#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !(defined(BOOST_GCC) && BOOST_GCC < 40600)
45
46 test2( boost::protect( f: Y() ) );
47
48#endif
49
50 return boost::report_errors();
51}
52

source code of boost/libs/bind/test/protect_test2.cpp