Brian Silverman | ce4aa8d | 2018-08-04 23:36:03 -0700 | [diff] [blame^] | 1 | #include <boost/config.hpp> |
| 2 | |
| 3 | #if defined(BOOST_MSVC) |
| 4 | #pragma warning(disable: 4786) // identifier truncated in debug info |
| 5 | #pragma warning(disable: 4710) // function not inlined |
| 6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion |
| 7 | #pragma warning(disable: 4514) // unreferenced inline removed |
| 8 | #endif |
| 9 | |
| 10 | // |
| 11 | // bind_rel_test.cpp - ==, !=, <, <=, >, >= operators |
| 12 | // |
| 13 | // Copyright (c) 2005 Peter Dimov |
| 14 | // |
| 15 | // Distributed under the Boost Software License, Version 1.0. (See |
| 16 | // accompanying file LICENSE_1_0.txt or copy at |
| 17 | // http://www.boost.org/LICENSE_1_0.txt) |
| 18 | // |
| 19 | |
| 20 | #include <boost/bind.hpp> |
| 21 | |
| 22 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
| 23 | #pragma warning(push, 3) |
| 24 | #endif |
| 25 | |
| 26 | #include <iostream> |
| 27 | |
| 28 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
| 29 | #pragma warning(pop) |
| 30 | #endif |
| 31 | |
| 32 | #include <boost/detail/lightweight_test.hpp> |
| 33 | |
| 34 | int f( int x ) |
| 35 | { |
| 36 | return x + x; |
| 37 | } |
| 38 | |
| 39 | int g( int x ) |
| 40 | { |
| 41 | return 2 * x; |
| 42 | } |
| 43 | |
| 44 | int main() |
| 45 | { |
| 46 | int x = 4; |
| 47 | int y = x + x; |
| 48 | |
| 49 | // bind op value |
| 50 | |
| 51 | BOOST_TEST( ( boost::bind( f, _1 ) == y )( x ) ); |
| 52 | BOOST_TEST( !( ( boost::bind( f, _1 ) != y )( x ) ) ); |
| 53 | |
| 54 | BOOST_TEST( !( ( boost::bind( f, _1 ) < y )( x ) ) ); |
| 55 | BOOST_TEST( ( boost::bind( f, _1 ) < y + 1 )( x ) ); |
| 56 | |
| 57 | BOOST_TEST( !( ( boost::bind( f, _1 ) > y )( x ) ) ); |
| 58 | BOOST_TEST( ( boost::bind( f, _1 ) > y - 1 )( x ) ); |
| 59 | |
| 60 | BOOST_TEST( !( ( boost::bind( f, _1 ) <= y - 1 )( x ) ) ); |
| 61 | BOOST_TEST( ( boost::bind( f, _1 ) <= y )( x ) ); |
| 62 | BOOST_TEST( ( boost::bind( f, _1 ) <= y + 1 )( x ) ); |
| 63 | |
| 64 | BOOST_TEST( !( ( boost::bind( f, _1 ) >= y + 1 )( x ) ) ); |
| 65 | BOOST_TEST( ( boost::bind( f, _1 ) >= y )( x ) ); |
| 66 | BOOST_TEST( ( boost::bind( f, _1 ) >= y - 1 )( x ) ); |
| 67 | |
| 68 | // bind op ref |
| 69 | |
| 70 | BOOST_TEST( ( boost::bind( f, _1 ) == boost::ref( y ) )( x ) ); |
| 71 | BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::ref( y ) )( x ) ) ); |
| 72 | BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::ref( y ) )( x ) ) ); |
| 73 | BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::ref( y ) )( x ) ) ); |
| 74 | BOOST_TEST( ( boost::bind( f, _1 ) <= boost::ref( y ) )( x ) ); |
| 75 | BOOST_TEST( ( boost::bind( f, _1 ) >= boost::ref( y ) )( x ) ); |
| 76 | |
| 77 | // bind op placeholder |
| 78 | |
| 79 | BOOST_TEST( ( boost::bind( f, _1 ) == _2 )( x, y ) ); |
| 80 | BOOST_TEST( !( ( boost::bind( f, _1 ) != _2 )( x, y ) ) ); |
| 81 | BOOST_TEST( !( ( boost::bind( f, _1 ) < _2 )( x, y ) ) ); |
| 82 | BOOST_TEST( !( ( boost::bind( f, _1 ) > _2 )( x, y ) ) ); |
| 83 | BOOST_TEST( ( boost::bind( f, _1 ) <= _2 )( x, y ) ); |
| 84 | BOOST_TEST( ( boost::bind( f, _1 ) >= _2 )( x, y ) ); |
| 85 | |
| 86 | // bind op bind |
| 87 | |
| 88 | // important: bind( f, _1 ) and bind( g, _1 ) have the same type |
| 89 | BOOST_TEST( ( boost::bind( f, _1 ) == boost::bind( g, _1 ) )( x ) ); |
| 90 | BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::bind( g, _1 ) )( x ) ) ); |
| 91 | BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::bind( g, _1 ) )( x ) ) ); |
| 92 | BOOST_TEST( ( boost::bind( f, _1 ) <= boost::bind( g, _1 ) )( x ) ); |
| 93 | BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::bind( g, _1 ) )( x ) ) ); |
| 94 | BOOST_TEST( ( boost::bind( f, _1 ) >= boost::bind( g, _1 ) )( x ) ); |
| 95 | |
| 96 | return boost::report_errors(); |
| 97 | } |