| 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 | #define _SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING |
| 6 | |
| 7 | #include <boost/bind/protect.hpp> |
| 8 | #include <boost/core/lightweight_test.hpp> |
| 9 | #include <boost/config.hpp> |
| 10 | #include <boost/config/workaround.hpp> |
| 11 | #include <functional> |
| 12 | |
| 13 | // |
| 14 | |
| 15 | int main() |
| 16 | { |
| 17 | BOOST_TEST_EQ( boost::protect( std::plus<int>() )( 1, 2 ), 3 ); |
| 18 | BOOST_TEST_EQ( boost::protect( std::minus<int>() )( 1, 2 ), -1 ); |
| 19 | BOOST_TEST_EQ( boost::protect( std::multiplies<int>() )( 1, 2 ), 2 ); |
| 20 | BOOST_TEST_EQ( boost::protect( std::divides<int>() )( 1, 2 ), 0 ); |
| 21 | BOOST_TEST_EQ( boost::protect( std::modulus<int>() )( 1, 2 ), 1 ); |
| 22 | BOOST_TEST_EQ( boost::protect( std::negate<int>() )( 1 ), -1 ); |
| 23 | |
| 24 | BOOST_TEST_EQ( boost::protect( std::equal_to<int>() )( 1, 2 ), false ); |
| 25 | BOOST_TEST_EQ( boost::protect( std::not_equal_to<int>() )( 1, 2 ), true ); |
| 26 | BOOST_TEST_EQ( boost::protect( std::greater<int>() )( 1, 2 ), false ); |
| 27 | BOOST_TEST_EQ( boost::protect( std::less<int>() )( 1, 2 ), true ); |
| 28 | BOOST_TEST_EQ( boost::protect( std::greater_equal<int>() )( 1, 2 ), false ); |
| 29 | BOOST_TEST_EQ( boost::protect( std::less_equal<int>() )( 1, 2 ), true ); |
| 30 | |
| 31 | BOOST_TEST_EQ( boost::protect( std::logical_and<int>() )( 1, 2 ), true ); |
| 32 | BOOST_TEST_EQ( boost::protect( std::logical_or<int>() )( 1, 2 ), true ); |
| 33 | BOOST_TEST_EQ( boost::protect( std::logical_not<int>() )( 1 ), false ); |
| 34 | |
| 35 | #if !BOOST_WORKAROUND(BOOST_MSVC, < 1600) |
| 36 | |
| 37 | BOOST_TEST_EQ( boost::protect( std::bit_and<int>() )( 1, 2 ), 0 ); |
| 38 | BOOST_TEST_EQ( boost::protect( std::bit_or<int>() )( 1, 2 ), 3 ); |
| 39 | BOOST_TEST_EQ( boost::protect( std::bit_xor<int>() )( 1, 2 ), 3 ); |
| 40 | |
| 41 | #endif |
| 42 | |
| 43 | return boost::report_errors(); |
| 44 | } |
| 45 | |