1 | |
2 | // Copyright Aleksey Gurtovoy 2003-2004 |
3 | // Copyright Jaap Suter 2003 |
4 | // |
5 | // Distributed under the Boost Software License,Version 1.0. |
6 | // (See accompanying file LICENSE_1_0.txt or copy at |
7 | // http://www.boost.org/LICENSE_1_0.txt) |
8 | // |
9 | // See http://www.boost.org/libs/mpl for documentation. |
10 | |
11 | // $Id$ |
12 | // $Date$ |
13 | // $Revision$ |
14 | |
15 | #include <boost/mpl/bitwise.hpp> |
16 | #include <boost/mpl/integral_c.hpp> |
17 | #include <boost/mpl/aux_/test.hpp> |
18 | |
19 | typedef integral_c<unsigned int, 0> _0; |
20 | typedef integral_c<unsigned int, 1> _1; |
21 | typedef integral_c<unsigned int, 2> _2; |
22 | typedef integral_c<unsigned int, 8> _8; |
23 | typedef integral_c<unsigned int, 0xffffffff> _ffffffff; |
24 | |
25 | MPL_TEST_CASE() |
26 | { |
27 | MPL_ASSERT_RELATION( (bitand_<_0,_0>::value), ==, 0 ); |
28 | MPL_ASSERT_RELATION( (bitand_<_1,_0>::value), ==, 0 ); |
29 | MPL_ASSERT_RELATION( (bitand_<_0,_1>::value), ==, 0 ); |
30 | MPL_ASSERT_RELATION( (bitand_<_0,_ffffffff>::value), ==, 0 ); |
31 | MPL_ASSERT_RELATION( (bitand_<_1,_ffffffff>::value), ==, 1 ); |
32 | MPL_ASSERT_RELATION( (bitand_<_8,_ffffffff>::value), ==, 8 ); |
33 | } |
34 | |
35 | MPL_TEST_CASE() |
36 | { |
37 | MPL_ASSERT_RELATION( (bitor_<_0,_0>::value), ==, 0 ); |
38 | MPL_ASSERT_RELATION( (bitor_<_1,_0>::value), ==, 1 ); |
39 | MPL_ASSERT_RELATION( (bitor_<_0,_1>::value), ==, 1 ); |
40 | MPL_ASSERT_RELATION( static_cast<long>(bitor_<_0,_ffffffff>::value), ==, static_cast<long>(0xffffffff) ); |
41 | MPL_ASSERT_RELATION( static_cast<long>(bitor_<_1,_ffffffff>::value), ==, static_cast<long>(0xffffffff) ); |
42 | MPL_ASSERT_RELATION( static_cast<long>(bitor_<_8,_ffffffff>::value), ==, static_cast<long>(0xffffffff) ); |
43 | } |
44 | |
45 | MPL_TEST_CASE() |
46 | { |
47 | MPL_ASSERT_RELATION( (bitxor_<_0,_0>::value), ==, 0 ); |
48 | MPL_ASSERT_RELATION( (bitxor_<_1,_0>::value), ==, 1 ); |
49 | MPL_ASSERT_RELATION( (bitxor_<_0,_1>::value), ==, 1 ); |
50 | MPL_ASSERT_RELATION( static_cast<long>(bitxor_<_0,_ffffffff>::value), ==, static_cast<long>(0xffffffff ^ 0) ); |
51 | MPL_ASSERT_RELATION( static_cast<long>(bitxor_<_1,_ffffffff>::value), ==, static_cast<long>(0xffffffff ^ 1) ); |
52 | MPL_ASSERT_RELATION( static_cast<long>(bitxor_<_8,_ffffffff>::value), ==, static_cast<long>(0xffffffff ^ 8) ); |
53 | } |
54 | |
55 | MPL_TEST_CASE() |
56 | { |
57 | MPL_ASSERT_RELATION( (shift_right<_0,_0>::value), ==, 0 ); |
58 | MPL_ASSERT_RELATION( (shift_right<_1,_0>::value), ==, 1 ); |
59 | MPL_ASSERT_RELATION( (shift_right<_1,_1>::value), ==, 0 ); |
60 | MPL_ASSERT_RELATION( (shift_right<_2,_1>::value), ==, 1 ); |
61 | MPL_ASSERT_RELATION( (shift_right<_8,_1>::value), ==, 4 ); |
62 | } |
63 | |
64 | MPL_TEST_CASE() |
65 | { |
66 | MPL_ASSERT_RELATION( (shift_left<_0,_0>::value), ==, 0 ); |
67 | MPL_ASSERT_RELATION( (shift_left<_1,_0>::value), ==, 1 ); |
68 | MPL_ASSERT_RELATION( (shift_left<_1,_1>::value), ==, 2 ); |
69 | MPL_ASSERT_RELATION( (shift_left<_2,_1>::value), ==, 4 ); |
70 | MPL_ASSERT_RELATION( (shift_left<_8,_1>::value), ==, 16 ); |
71 | } |
72 | |