2
0
mirror of https://github.com/boostorg/phoenix.git synced 2026-02-18 14:22:09 +00:00

Update master with release-3.1.1

This commit is contained in:
John Fletcher
2015-02-23 11:53:46 +00:00
parent 7567ac6f6a
commit b2fff2c41d
69 changed files with 5040 additions and 338 deletions

View File

@@ -0,0 +1,53 @@
////////////////////////////////////////////////////////////////////////////
// lazy_argument_tests.cpp
//
// lazy argument tests passing lazy function as argument.
//
////////////////////////////////////////////////////////////////////////////
/*=============================================================================
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 <boost/phoenix/core/limits.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/function.hpp>
namespace example {
struct G {
template <typename Sig>
struct result;
template <typename This, typename A0>
struct result<This(A0)>
: boost::remove_reference<A0>
{};
template <typename T>
T operator()(T t) const { return ++t; }
};
}
typedef boost::phoenix::function<example::G> GG;
boost::phoenix::function<example::G> gg;
template <typename F,typename T>
T h(F f, T const& t)
{
return f(t)();
}
int main()
{
BOOST_TEST( h(gg,1) == 2);
BOOST_TEST(( h<GG,int>(gg,1) == 2));
return boost::report_errors();
}

View File

@@ -0,0 +1,109 @@
////////////////////////////////////////////////////////////////////////////
// lazy_make_pair_tests.cpp
//
// lazy make_pair test solving the optimizer problem.
//
////////////////////////////////////////////////////////////////////////////
/*=============================================================================
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 <boost/phoenix/core/limits.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/function.hpp>
namespace boost {
namespace phoenix {
#ifdef BOOST_RESULT_OF_USE_TR1
namespace result_of {
template <
typename Arg1
, typename Arg2
>
class make_pair
{
public:
typedef typename boost::remove_reference<Arg1>::type Arg1Type;
typedef typename boost::remove_reference<Arg2>::type Arg2Type;
typedef std::pair<Arg1Type,Arg2Type> type;
};
}
#endif
namespace impl
{
struct make_pair {
#ifdef BOOST_RESULT_OF_USE_TR1
template <typename Sig>
struct result;
// This fails with -O2 unless refs are removed from A1 and A2.
template <typename This, typename A0, typename A1>
struct result<This(A0, A1)>
{
typedef typename result_of::make_pair<A0,A1>::type type;
};
#else
template <typename Sig>
struct result;
template <typename This, typename A0, typename A1>
struct result<This(A0, A1)>
: boost::remove_reference<std::pair<A0, A1> >
{};
#endif
template <typename A0, typename A1>
#ifdef BOOST_RESULT_OF_USE_TR1
typename result<make_pair(A0,A1)>::type
#else
std::pair<A0, A1>
#endif
operator()(A0 const & a0, A1 const & a1) const
{
return std::make_pair(a0,a1);
}
};
}
BOOST_PHOENIX_ADAPT_CALLABLE(make_pair, impl::make_pair, 2)
}
}
int main()
{
namespace phx = boost::phoenix;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int a = 99; int b = 256;
std::pair<int,int> ab1 = phx::make_pair(a,b)();
//std::cout << ab1.first << "," << ab1.second << std::endl;
BOOST_TEST(ab1.first == 99 && ab1.second == 256);
std::pair<int,int> ab2 = phx::make_pair(arg1,b)(a);
//std::cout << ab2.first << "," << ab2.second << std::endl;
BOOST_TEST(ab2.first == 99 && ab2.second == 256);
std::pair<int,int> ab3 = phx::make_pair(arg1,arg2)(a,b);
//std::cout << ab3.first << "," << ab3.second << std::endl;
BOOST_TEST(ab3.first == 99 && ab3.second == 256);
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
////////////////////////////////////////////////////////////////////////////
// lazy_templated_struct_tests.cpp
//
// lazy templated struct test to check this works everywhere.
//
////////////////////////////////////////////////////////////////////////////
/*=============================================================================
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 <boost/phoenix/core/limits.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/function.hpp>
#include <boost/function.hpp>
namespace example {
namespace impl {
// Example of templated struct.
template <typename Result>
struct what {
typedef Result result_type;
Result operator()(Result const & r) const
{
return r;
}
};
template <typename Result>
struct what0 {
typedef Result result_type;
Result operator()() const
{
return Result(100);
}
};
}
boost::function1<int, int > what_int = impl::what<int>();
boost::function0<int> what0_int = impl::what0<int>();
BOOST_PHOENIX_ADAPT_FUNCTION(int,what,what_int,1)
BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(int,what0,what0_int)
}
int main()
{
int a = 99;
using boost::phoenix::arg_names::arg1;
BOOST_TEST(example::what_int(a) == a);
BOOST_TEST(example::what(a)() == a);
BOOST_TEST(example::what(arg1)(a) == a);
BOOST_TEST(example::what0_int() == 100);
BOOST_TEST(example::what0()() == 100);
return boost::report_errors();
}