1 /*==============================================================================
2     Copyright (c) 2008 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/phoenix/core.hpp>
11 #include <boost/phoenix/bind.hpp>
12 #include <boost/phoenix/operator.hpp>
13 
14 #include <iostream>
15 #include <boost/detail/lightweight_test.hpp>
16 
17 bool
f(bool x)18 f(bool x)
19 {
20     return x;
21 }
22 
23 bool
g(bool x)24 g(bool x)
25 {
26     return !x;
27 }
28 
29 bool
h()30 h()
31 {
32     BOOST_ERROR("Short-circuit evaluation failure");
33     return false;
34 }
35 
36 template <typename F, typename A1, typename A2, typename R>
37 void
tester(F f,A1 a1,A2 a2,R r)38 tester(F f, A1 a1, A2 a2, R r)
39 {
40     BOOST_TEST(f(a1, a2) == r);
41 }
42 
main()43 int main()
44 {
45     using boost::phoenix::bind;
46     using boost::phoenix::placeholders::_1;
47     using boost::phoenix::placeholders::_2;
48 
49     // &&
50 
51     tester(bind(f, true) && bind(g, true), false, false, f(true) && g(true));
52     tester(bind(f, true) && bind(g, false), false, false, f(true) && g(false));
53 
54     tester(bind(f, false) && bind(h), false, false, f(false) && h());
55 
56     tester(bind(f, _1) && bind(g, _2), true, true, f(true) && g(true));
57     tester(bind(f, _1) && bind(g, _2), true, false, f(true) && g(false));
58 
59     tester(bind(f, _1) && bind(h), false, false, f(false) && h());
60 
61     // ||
62 
63     tester(bind(f, false) || bind(g, true), false, false, f(false) || g(true));
64 
65     tester(bind(f, false) || bind(g, false), false, false, f(false) || g(false));
66 
67     tester(bind(f, true) || bind(h), false, false, f(true) || h());
68 
69     tester(bind(f, _1) || bind(g, _2), false, true, f(false) || g(true));
70     tester(bind(f, _1) || bind(g, _2), false, false, f(false) || g(false));
71 
72     tester(bind(f, _1) || bind(h), true, false, f(true) || h());
73 
74     //
75 
76     return boost::report_errors();
77 }
78