]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/function/lazy_make_pair_tests.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / phoenix / test / function / lazy_make_pair_tests.cpp
1 ////////////////////////////////////////////////////////////////////////////
2 // lazy_make_pair_tests.cpp
3 //
4 // lazy make_pair test solving the optimizer problem.
5 //
6 ////////////////////////////////////////////////////////////////////////////
7 /*=============================================================================
8 Copyright (c) 2001-2007 Joel de Guzman
9 Copyright (c) 2015 John Fletcher
10
11 Distributed under the Boost Software License, Version 1.0. (See accompanying
12 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 ==============================================================================*/
14
15 #include <boost/phoenix/core/limits.hpp>
16
17 #include <boost/detail/lightweight_test.hpp>
18 #include <boost/phoenix/core.hpp>
19 #include <boost/phoenix/function.hpp>
20
21 namespace boost {
22
23 namespace phoenix {
24
25 #ifdef BOOST_RESULT_OF_USE_TR1
26
27 namespace result_of {
28
29 template <
30 typename Arg1
31 , typename Arg2
32 >
33 class make_pair
34 {
35 public:
36 typedef typename boost::remove_reference<Arg1>::type Arg1Type;
37 typedef typename boost::remove_reference<Arg2>::type Arg2Type;
38 typedef std::pair<Arg1Type,Arg2Type> type;
39 };
40 }
41 #endif
42
43 namespace impl
44 {
45
46 struct make_pair {
47
48
49 #ifdef BOOST_RESULT_OF_USE_TR1
50 template <typename Sig>
51 struct result;
52 // This fails with -O2 unless refs are removed from A1 and A2.
53 template <typename This, typename A0, typename A1>
54 struct result<This(A0, A1)>
55 {
56 typedef typename result_of::make_pair<A0,A1>::type type;
57 };
58 #else
59 template <typename Sig>
60 struct result;
61
62 template <typename This, typename A0, typename A1>
63 struct result<This(A0, A1)>
64 : boost::remove_reference<std::pair<A0, A1> >
65 {};
66
67 #endif
68
69
70 template <typename A0, typename A1>
71 #ifdef BOOST_RESULT_OF_USE_TR1
72 typename result<make_pair(A0,A1)>::type
73 #else
74 std::pair<A0, A1>
75 #endif
76 operator()(A0 const & a0, A1 const & a1) const
77 {
78 return std::make_pair(a0,a1);
79 }
80
81 };
82 }
83
84 BOOST_PHOENIX_ADAPT_CALLABLE(make_pair, impl::make_pair, 2)
85
86 }
87
88 }
89
90 int main()
91 {
92 namespace phx = boost::phoenix;
93 using boost::phoenix::arg_names::arg1;
94 using boost::phoenix::arg_names::arg2;
95 int a = 99; int b = 256;
96
97 std::pair<int,int> ab1 = phx::make_pair(a,b)();
98 //std::cout << ab1.first << "," << ab1.second << std::endl;
99 BOOST_TEST(ab1.first == 99 && ab1.second == 256);
100 std::pair<int,int> ab2 = phx::make_pair(arg1,b)(a);
101 //std::cout << ab2.first << "," << ab2.second << std::endl;
102 BOOST_TEST(ab2.first == 99 && ab2.second == 256);
103 std::pair<int,int> ab3 = phx::make_pair(arg1,arg2)(a,b);
104 //std::cout << ab3.first << "," << ab3.second << std::endl;
105 BOOST_TEST(ab3.first == 99 && ab3.second == 256);
106
107
108 return boost::report_errors();
109 }