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