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