bitwise_tests.cpp 2.0 KB

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