more_let_tests2a.cpp 3.5 KB

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