bitwise.cpp 2.7 KB

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