1 /*============================================================================= 2 Copyright (c) 2001-2007 Joel de Guzman 3 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 12 #include <boost/phoenix/core/limits.hpp> 13 14 #include <boost/detail/lightweight_test.hpp> 15 #include <boost/fusion/tuple.hpp> 16 #include <boost/phoenix/core.hpp> 17 #include <boost/phoenix/operator.hpp> 18 #include <boost/phoenix/function.hpp> 19 #include <boost/phoenix/fusion.hpp> 20 #include <boost/phoenix/scope.hpp> 21 22 #include <typeinfo> 23 24 namespace fusion = boost::fusion; 25 namespace mpl = boost::mpl; 26 27 int main()28main() 29 { 30 using boost::phoenix::let; 31 using boost::phoenix::val; 32 using boost::phoenix::arg_names::_1; 33 using boost::phoenix::local_names::_a; 34 using boost::phoenix::local_names::_b; 35 /* 36 { 37 // show that we can return a local from an outer scope 38 int y = 0; 39 int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y); 40 41 BOOST_TEST(x == 1); 42 } 43 { 44 // show that we can return a local from an inner scope 45 int y = 1; 46 int x = (let(_a = 0)[let(_b = _1)[ _b ]])(y); 47 48 BOOST_TEST(x == 1); 49 } 50 { 51 // show that we can return a local from an outer scope 52 //int y = 0; 53 int x = (let(_a = 1)[let(_b = _a)[ _a ]])(); 54 55 BOOST_TEST(x == 1); 56 } 57 { 58 // show that we can return a local from an inner scope 59 //int y = 0; 60 int x = (let(_a = 1)[let(_b = _a)[ _b ]])(); 61 62 BOOST_TEST(x == 1); 63 } 64 { 65 // show that we can return a local from an outer scope 66 int y = 1; 67 int x = (let(_a = _1)[let(_b = _a)[ _a ]])(y); 68 69 BOOST_TEST(x == 1); 70 } 71 { 72 // show that we can return a local from an inner scope 73 int y = 1; 74 int x = (let(_a = _1)[let(_b = _a)[ _b ]])(y); 75 76 BOOST_TEST(x == 1); 77 } 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 { 116 int y = 0; 117 int x = (let(_a = 1, _b = 2)[let(_b = _1)[ _a ]])(y); 118 // std::cout << x << " Q "; // clang 4201472 119 BOOST_TEST(x == 1); 120 } 121 122 123 return boost::report_errors(); 124 } 125 126