more_let_tests2b.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Copyright (c) 2015 John Fletcher
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #include <iostream>
  8. #include <cmath>
  9. #include <algorithm>
  10. #include <vector>
  11. #include <boost/phoenix/core/limits.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. #include <boost/fusion/tuple.hpp>
  14. #include <boost/phoenix/core.hpp>
  15. #include <boost/phoenix/operator.hpp>
  16. #include <boost/phoenix/function.hpp>
  17. #include <boost/phoenix/fusion.hpp>
  18. #include <boost/phoenix/scope.hpp>
  19. #include <typeinfo>
  20. namespace fusion = boost::fusion;
  21. namespace mpl = boost::mpl;
  22. int
  23. main()
  24. {
  25. using boost::phoenix::let;
  26. using boost::phoenix::val;
  27. using boost::phoenix::arg_names::_1;
  28. using boost::phoenix::arg_names::_2;
  29. using boost::phoenix::local_names::_a;
  30. using boost::phoenix::local_names::_b;
  31. /*
  32. {
  33. // show that we can return a local from an outer scope
  34. int y = 0;
  35. int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);
  36. BOOST_TEST(x == 1);
  37. }
  38. {
  39. // show that we can return a local from an inner scope
  40. int y = 1;
  41. int x = (let(_a = 0)[let(_b = _1)[ _b ]])(y);
  42. BOOST_TEST(x == 1);
  43. }
  44. {
  45. // show that we can return a local from an outer scope
  46. //int y = 0;
  47. int x = (let(_a = 1)[let(_b = _a)[ _a ]])();
  48. BOOST_TEST(x == 1);
  49. }
  50. {
  51. // show that we can return a local from an inner scope
  52. //int y = 0;
  53. int x = (let(_a = 1)[let(_b = _a)[ _b ]])();
  54. BOOST_TEST(x == 1);
  55. }
  56. {
  57. // show that we can return a local from an outer scope
  58. int y = 1;
  59. int x = (let(_a = _1)[let(_b = _a)[ _a ]])(y);
  60. BOOST_TEST(x == 1);
  61. }
  62. {
  63. // show that we can return a local from an inner scope
  64. int y = 1;
  65. int x = (let(_a = _1)[let(_b = _a)[ _b ]])(y);
  66. BOOST_TEST(x == 1);
  67. }
  68. */
  69. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70. // Be very careful. Some of these cases give a silly answer
  71. // with clang 3.4 with C++03 and work for C++11.
  72. // gcc 4.8.2 seems O.K. both ways. Oh dear.
  73. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. /*{
  75. int y = 0;
  76. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _a ]])(y);
  77. //std::cout << x << " P1A "; //clang - empty memory
  78. BOOST_TEST(x == 1);
  79. }
  80. {
  81. int y = 0;
  82. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _b ]])(y);
  83. //std::cout << x << " P1B "; //clang - 42 value- one step better
  84. BOOST_TEST(x == 1);
  85. }
  86. {
  87. int y = 0;
  88. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _a ]])(y);
  89. //std::cout << x << " P2A "; //clang - 42 value - one step better
  90. BOOST_TEST(x == 1);
  91. }*/
  92. {
  93. int y = 0;
  94. #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
  95. //int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
  96. #else
  97. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
  98. //std::cout << x << " P2B "; //clang - 42 value - one step better
  99. BOOST_TEST(x == 1);
  100. #endif
  101. }
  102. {
  103. int y = 1;
  104. int x = (let(_a = _1, _b = val(2))[let(_b = _a)[ _a ]])(y);
  105. //std::cout << x << " P3 "; //clang - OK - one step better still
  106. BOOST_TEST(x == 1);
  107. }
  108. {
  109. int y = 0;
  110. #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
  111. int z = 2;
  112. int x = (let(_a = _1, _b = _2)[let(_b = _1)[ _a ]])(y,z);
  113. #else
  114. int x = (let(_a = 1, _b = 2)[let(_b = _1)[ _a ]])(y);
  115. #endif
  116. // std::cout << x << " Q "; // clang 4201472
  117. BOOST_TEST(x == 1);
  118. }
  119. return boost::report_errors();
  120. }