more_let_tests1.cpp 3.9 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. // show that we can return a local from an outer scope
  33. int y = 0;
  34. #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
  35. int x = (let(_a = _2)[let(_b = _1)[ _a ]])(y,1);
  36. #else
  37. int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);
  38. #endif
  39. BOOST_TEST(x == 1);
  40. }
  41. {
  42. // show that we can return a local from an inner scope
  43. int y = 1;
  44. int x = (let(_a = 0)[let(_b = _1)[ _b ]])(y);
  45. BOOST_TEST(x == 1);
  46. }
  47. {
  48. // show that we can return a local from an outer scope
  49. //int y = 0;
  50. #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
  51. int x = (let(_a = 1)[let(_b = _a)[ _a ]])();
  52. #else
  53. int x = (let(_a = _1)[let(_b = _a)[ _a ]])(1);
  54. #endif
  55. BOOST_TEST(x == 1);
  56. }
  57. {
  58. // show that we can return a local from an inner scope
  59. //int y = 0;
  60. #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
  61. int x = (let(_a = _1)[let(_b = _a)[ _b ]])(1);
  62. #else
  63. int x = (let(_a = 1)[let(_b = _a)[ _b ]])();
  64. #endif
  65. BOOST_TEST(x == 1);
  66. }
  67. {
  68. // show that we can return a local from an outer scope
  69. int y = 1;
  70. int x = (let(_a = _1)[let(_b = _a)[ _a ]])(y);
  71. BOOST_TEST(x == 1);
  72. }
  73. {
  74. // show that we can return a local from an inner scope
  75. int y = 1;
  76. int x = (let(_a = _1)[let(_b = _a)[ _b ]])(y);
  77. BOOST_TEST(x == 1);
  78. }
  79. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. // Be very careful. Some of these cases give a silly answer
  81. // with clang 3.4 with C++03 and work for C++11.
  82. // gcc 4.8.2 seems O.K. both ways. Oh dear.
  83. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84. /* {
  85. int y = 0;
  86. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _a ]])(y);
  87. //std::cout << x << " P1A "; //clang - empty memory
  88. BOOST_TEST(x == 1);
  89. }
  90. {
  91. int y = 0;
  92. int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _b ]])(y);
  93. //std::cout << x << " P1B "; //clang - 42 value- one step better
  94. BOOST_TEST(x == 1);
  95. }
  96. {
  97. int y = 0;
  98. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _a ]])(y);
  99. //std::cout << x << " P2A "; //clang - 42 value - one step better
  100. BOOST_TEST(x == 1);
  101. }
  102. {
  103. int y = 0;
  104. int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
  105. //std::cout << x << " P2B "; //clang - 42 value - one step better
  106. BOOST_TEST(x == 1);
  107. }
  108. {
  109. int y = 1;
  110. int x = (let(_a = _1, _b = val(2))[let(_b = _a)[ _a ]])(y);
  111. //std::cout << x << " P3 "; //clang - OK - one step better still
  112. BOOST_TEST(x == 1);
  113. }
  114. {
  115. int y = 0;
  116. int x = (let(_a = 1, _b = 2)[let(_b = _1)[ _a ]])(y);
  117. // std::cout << x << " Q "; // clang 4201472
  118. BOOST_TEST(x == 1);
  119. }
  120. */
  121. return boost::report_errors();
  122. }