PageRenderTime 39ms CodeModel.GetById 31ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/operator/bitwise_tests.cpp

http://hadesmem.googlecode.com/
C++ | 76 lines | 58 code | 12 blank | 6 comment | 17 complexity | 66f9e11d4c05c862521fd5c518f933a5 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2007 Joel de Guzman
 3
 4    Distributed under the Boost Software License, Version 1.0. (See accompanying 
 5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 6==============================================================================*/
 7#include <iostream>
 8#include <boost/detail/lightweight_test.hpp>
 9#include <boost/phoenix/core.hpp>
10#include <boost/phoenix/operator.hpp>
11
12namespace phoenix = boost::phoenix;
13
14int
15main()
16{
17    using phoenix::ref;
18    using phoenix::val;
19    using phoenix::arg_names::arg1;
20    using std::cout;
21
22    {
23        int x;
24        int y;
25
26        x = 123;
27        y = 123;
28        (ref(x) &= 456)();
29        y &= 456;
30        BOOST_TEST(x == y);
31
32        x = 123;
33        y = 123;
34        (ref(x) |= 456)();
35        y |= 456;
36        BOOST_TEST(x == y);
37
38        x = 123;
39        y = 123;
40        (ref(x) ^= 456)();
41        y ^= 456;
42        BOOST_TEST(x == y);
43
44        x = 123;
45        y = 123;
46        (ref(x) <<= 4)();
47        y <<= 4;
48        BOOST_TEST(x == y);
49
50        x = 1230000;
51        y = 1230000;
52        (ref(x) >>= 4)();
53        y >>= 4;
54        BOOST_TEST(x == y);
55
56        int& r1 = (ref(x) &= 456)(); // should be an lvalue
57        int& r2 = (ref(x) |= 456)(); // should be an lvalue
58        int& r3 = (ref(x) ^= 456)(); // should be an lvalue
59        int& r4 = (ref(x) <<= 4)(); // should be an lvalue
60        int& r5 = (ref(x) >>= 4)(); // should be an lvalue
61        BOOST_TEST(&r1 == &r2 && &r2 == &r3 && &r3 == &r4 && &r4 == &r5);
62    }
63
64    {
65        BOOST_TEST((val(123) & 456)() == (123 & 456));
66        BOOST_TEST((val(123) | 456)() == (123 | 456));
67        BOOST_TEST((val(123) ^ 456)() == (123 ^ 456));
68        BOOST_TEST((val(123) << 4)() == (123 << 4));
69        BOOST_TEST((val(1230000) >> 4)() == (1230000 >> 4));
70
71        char const* s = "Yabadabadoo!!!\n";
72        (cout << arg1)(s);
73    }
74
75    return boost::report_errors();
76}