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