if_else_tests.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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 <boost/detail/lightweight_test.hpp>
  7. #include <boost/phoenix/core.hpp>
  8. #include <boost/phoenix/operator.hpp>
  9. namespace phoenix = boost::phoenix;
  10. int
  11. main()
  12. {
  13. //using phoenix::if_else;
  14. using phoenix::ref;
  15. using phoenix::val;
  16. using phoenix::arg_names::arg1;
  17. {
  18. int x = 0;
  19. int y = 0;
  20. bool c = false;
  21. BOOST_TEST(phoenix::if_else(arg1, 1234, 5678)(c) == 5678);
  22. BOOST_TEST(phoenix::if_else(arg1, 1234, 'x')(c) == 'x');
  23. int& r = phoenix::if_else(arg1, ref(x), ref(y))(c); // should be an lvalue
  24. BOOST_TEST(&y == &r);
  25. (phoenix::if_else(arg1, ref(x), ref(y)) = 986754321)(c);
  26. BOOST_TEST(y == 986754321);
  27. }
  28. return boost::report_errors();
  29. }