• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt)
4 
5 #include <boost/bind/protect.hpp>
6 #include <boost/core/lightweight_test.hpp>
7 #include <boost/config.hpp>
8 #include <boost/config/workaround.hpp>
9 #include <functional>
10 
11 //
12 
main()13 int main()
14 {
15     BOOST_TEST_EQ( boost::protect( std::plus<int>() )( 1, 2 ), 3 );
16     BOOST_TEST_EQ( boost::protect( std::minus<int>() )( 1, 2 ), -1 );
17     BOOST_TEST_EQ( boost::protect( std::multiplies<int>() )( 1, 2 ), 2 );
18     BOOST_TEST_EQ( boost::protect( std::divides<int>() )( 1, 2 ), 0 );
19     BOOST_TEST_EQ( boost::protect( std::modulus<int>() )( 1, 2 ), 1 );
20     BOOST_TEST_EQ( boost::protect( std::negate<int>() )( 1 ), -1 );
21 
22     BOOST_TEST_EQ( boost::protect( std::equal_to<int>() )( 1, 2 ), false );
23     BOOST_TEST_EQ( boost::protect( std::not_equal_to<int>() )( 1, 2 ), true );
24     BOOST_TEST_EQ( boost::protect( std::greater<int>() )( 1, 2 ), false );
25     BOOST_TEST_EQ( boost::protect( std::less<int>() )( 1, 2 ), true );
26     BOOST_TEST_EQ( boost::protect( std::greater_equal<int>() )( 1, 2 ), false );
27     BOOST_TEST_EQ( boost::protect( std::less_equal<int>() )( 1, 2 ), true );
28 
29     BOOST_TEST_EQ( boost::protect( std::logical_and<int>() )( 1, 2 ), true );
30     BOOST_TEST_EQ( boost::protect( std::logical_or<int>() )( 1, 2 ), true );
31     BOOST_TEST_EQ( boost::protect( std::logical_not<int>() )( 1 ), false );
32 
33 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1600)
34 
35     BOOST_TEST_EQ( boost::protect( std::bit_and<int>() )( 1, 2 ), 0 );
36     BOOST_TEST_EQ( boost::protect( std::bit_or<int>() )( 1, 2 ), 3 );
37     BOOST_TEST_EQ( boost::protect( std::bit_xor<int>() )( 1, 2 ), 3 );
38 
39 #endif
40 
41     return boost::report_errors();
42 }
43