| 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/bind.hpp> |
| 21 | #include <boost/core/lightweight_test.hpp> |
| 22 | |
| 23 | using namespace boost::placeholders; |
| 24 | |
| 25 | // |
| 26 | |
| 27 | int f( int x ) |
| 28 | { |
| 29 | return x + x; |
| 30 | } |
| 31 | |
| 32 | int g( int x ) |
| 33 | { |
| 34 | return 2 * x; |
| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | int x = 4; |
| 40 | int y = x + x; |
| 41 | |
| 42 | // bind op value |
| 43 | |
| 44 | BOOST_TEST( ( boost::bind( f, _1 ) == y )( x ) ); |
| 45 | BOOST_TEST( !( ( boost::bind( f, _1 ) != y )( x ) ) ); |
| 46 | |
| 47 | BOOST_TEST( !( ( boost::bind( f, _1 ) < y )( x ) ) ); |
| 48 | BOOST_TEST( ( boost::bind( f, _1 ) < y + 1 )( x ) ); |
| 49 | |
| 50 | BOOST_TEST( !( ( boost::bind( f, _1 ) > y )( x ) ) ); |
| 51 | BOOST_TEST( ( boost::bind( f, _1 ) > y - 1 )( x ) ); |
| 52 | |
| 53 | BOOST_TEST( !( ( boost::bind( f, _1 ) <= y - 1 )( x ) ) ); |
| 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 + 1 )( x ) ) ); |
| 58 | BOOST_TEST( ( boost::bind( f, _1 ) >= y )( x ) ); |
| 59 | BOOST_TEST( ( boost::bind( f, _1 ) >= y - 1 )( x ) ); |
| 60 | |
| 61 | // bind op ref |
| 62 | |
| 63 | BOOST_TEST( ( boost::bind( f, _1 ) == boost::ref( y ) )( x ) ); |
| 64 | BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::ref( y ) )( x ) ) ); |
| 65 | BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::ref( y ) )( x ) ) ); |
| 66 | BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::ref( y ) )( x ) ) ); |
| 67 | BOOST_TEST( ( boost::bind( f, _1 ) <= boost::ref( y ) )( x ) ); |
| 68 | BOOST_TEST( ( boost::bind( f, _1 ) >= boost::ref( y ) )( x ) ); |
| 69 | |
| 70 | // bind op placeholder |
| 71 | |
| 72 | BOOST_TEST( ( boost::bind( f, _1 ) == _2 )( x, y ) ); |
| 73 | BOOST_TEST( !( ( boost::bind( f, _1 ) != _2 )( x, y ) ) ); |
| 74 | BOOST_TEST( !( ( boost::bind( f, _1 ) < _2 )( x, y ) ) ); |
| 75 | BOOST_TEST( !( ( boost::bind( f, _1 ) > _2 )( x, y ) ) ); |
| 76 | BOOST_TEST( ( boost::bind( f, _1 ) <= _2 )( x, y ) ); |
| 77 | BOOST_TEST( ( boost::bind( f, _1 ) >= _2 )( x, y ) ); |
| 78 | |
| 79 | // bind op bind |
| 80 | |
| 81 | // important: bind( f, _1 ) and bind( g, _1 ) have the same type |
| 82 | BOOST_TEST( ( boost::bind( f, _1 ) == boost::bind( g, _1 ) )( x ) ); |
| 83 | BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::bind( g, _1 ) )( x ) ) ); |
| 84 | BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::bind( g, _1 ) )( x ) ) ); |
| 85 | BOOST_TEST( ( boost::bind( f, _1 ) <= boost::bind( g, _1 ) )( x ) ); |
| 86 | BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::bind( g, _1 ) )( x ) ) ); |
| 87 | BOOST_TEST( ( boost::bind( f, _1 ) >= boost::bind( g, _1 ) )( x ) ); |
| 88 | |
| 89 | return boost::report_errors(); |
| 90 | } |
| 91 | |