more_let_tests2.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <cmath>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <boost/phoenix/core/limits.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <boost/fusion/tuple.hpp>
  13. #include <boost/phoenix/core.hpp>
  14. #include <boost/phoenix/operator.hpp>
  15. #include <boost/phoenix/function.hpp>
  16. #include <boost/phoenix/fusion.hpp>
  17. #include <boost/phoenix/scope.hpp>
  18. #include <typeinfo>
  19. namespace fusion = boost::fusion;
  20. namespace mpl = boost::mpl;
  21. int
  22. main()
  23. {
  24. using boost::phoenix::let;
  25. using boost::phoenix::val;
  26. using boost::phoenix::arg_names::_1;
  27. using boost::phoenix::local_names::_a;
  28. using boost::phoenix::local_names::_b;
  29. /*
  30. {
  31. // show that we can return a local from an outer scope
  32. int y = 0;
  33. int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);
  34. BOOST_TEST(x == 1);
  35. }
  36. {
  37. // show that we can return a local from an inner scope
  38. int y = 1;
  39. int x = (let(_a = 0)[let(_b = _1)[ _b ]])(y);
  40. BOOST_TEST(x == 1);
  41. }
  42. {
  43. // show that we can return a local from an outer scope
  44. //int y = 0;
  45. int x = (let(_a = 1)[let(_b = _a)[ _a ]])();
  46. BOOST_TEST(x == 1);
  47. }
  48. {
  49. // show that we can return a local from an inner scope
  50. //int y = 0;
  51. int x = (let(_a = 1)[let(_b = _a)[ _b ]])();
  52. BOOST_TEST(x == 1);
  53. }
  54. {
  55. // show that we can return a local from an outer scope
  56. int y = 1;
  57. int x = (let(_a = _1)[let(_b = _a)[ _a ]])(y);
  58. BOOST_TEST(x == 1);
  59. }
  60. {
  61. // show that we can return a local from an inner scope
  62. int y = 1;
  63. int x = (let(_a = _1)[let(_b = _a)[ _b ]])(y);
  64. BOOST_TEST(x == 1);
  65. }
  66. */
  67. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68. // Be very careful. Some of these cases give a silly answer
  69. // with clang 3.4 with C++03 and work for C++11.
  70. // gcc 4.8.2 seems O.K. both ways. Oh dear.
  71. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  72. {
  73. int y = 0;
  74. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _a ]])(y);
  75. //std::cout << x << " P1A "; //clang - empty memory
  76. BOOST_TEST(x == 1);
  77. }
  78. {
  79. int y = 0;
  80. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _b ]])(y);
  81. //std::cout << x << " P1B "; //clang - 42 value- one step better
  82. BOOST_TEST(x == 1);
  83. }
  84. {
  85. int y = 0;
  86. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _a ]])(y);
  87. //std::cout << x << " P2A "; //clang - 42 value - one step better
  88. BOOST_TEST(x == 1);
  89. }
  90. {
  91. int y = 0;
  92. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
  93. //std::cout << x << " P2B "; //clang - 42 value - one step better
  94. BOOST_TEST(x == 1);
  95. }
  96. {
  97. int y = 1;
  98. int x = (let(_a = _1, _b = val(2))[let(_b = _a)[ _a ]])(y);
  99. //std::cout << x << " P3 "; //clang - OK - one step better still
  100. BOOST_TEST(x == 1);
  101. }
  102. {
  103. int y = 0;
  104. int x = (let(_a = 1, _b = 2)[let(_b = _1)[ _a ]])(y);
  105. // std::cout << x << " Q "; // clang 4201472
  106. BOOST_TEST(x == 1);
  107. }
  108. return boost::report_errors();
  109. }