PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/boost_bind_compatibility/bind_and_or_test.cpp

http://hadesmem.googlecode.com/
C++ | 77 lines | 46 code | 20 blank | 11 comment | 25 complexity | 6b80a81a30b2e59595b0555a96a99640 MD5 | raw file
 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
17bool
18f(bool x)
19{
20    return x;
21}
22
23bool
24g(bool x)
25{
26    return !x;
27}
28
29bool
30h()
31{
32    BOOST_ERROR("Short-circuit evaluation failure");
33    return false;
34}
35
36template <typename F, typename A1, typename A2, typename R>
37void
38tester(F f, A1 a1, A2 a2, R r)
39{
40    BOOST_TEST(f(a1, a2) == r);
41}
42
43int 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}