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