self_tests.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <vector>
  7. #include <string>
  8. #include <map>
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/phoenix/core.hpp>
  11. #include <boost/phoenix/operator.hpp>
  12. namespace phoenix = boost::phoenix;
  13. int
  14. main()
  15. {
  16. using phoenix::ref;
  17. using phoenix::arg_names::arg1;
  18. using phoenix::arg_names::arg2;
  19. using std::map;
  20. using std::string;
  21. using std::vector;
  22. {
  23. int x = 123;
  24. BOOST_TEST((&arg1)(x) == &x);
  25. //BOOST_TEST((*&arg1)(x) == 123);
  26. int y = 968;
  27. (ref(x) = arg1)(y);
  28. BOOST_TEST(x == y);
  29. (arg1 = 456)(x);
  30. BOOST_TEST(x == 456);
  31. int& r = (arg1 = 456)(x); // must be an lvalue
  32. BOOST_TEST(&r == &x);
  33. int c[] = { 1, 2, 3, 4, 5 };
  34. BOOST_TEST((arg1[3])(c) == 4);
  35. int& r2 = (arg1[3])(c); // must be an lvalue
  36. BOOST_TEST(&r2 == &c[3]);
  37. vector<string> v;
  38. v.push_back("a");
  39. v.push_back("b");
  40. v.push_back("c");
  41. v.push_back("d");
  42. BOOST_TEST((arg1[3])(v) == "d");
  43. map<string, int> m;
  44. (arg1["Kimpo"] = arg2)(m, x);
  45. BOOST_TEST(m["Kimpo"] == x);
  46. }
  47. return boost::report_errors();
  48. }