]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/doc/advanced/porting.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / phoenix / doc / advanced / porting.qbk
1 [/==============================================================================
2 Copyright (C) 2001-2010 Joel de Guzman
3 Copyright (C) 2001-2005 Dan Marsden
4 Copyright (C) 2001-2010 Thomas Heller
5
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ===============================================================================/]
9
10 [section Porting from Phoenix 2.0]
11
12 While reading the current documentation you might have noticed that the
13 [link phoenix.starter_kit Starter Kit] didn't change very much. This is because
14 a lot of effort was put into being compatible with Phoenix 2.0, at least on the
15 outside.
16
17 That being said, the only major difference is the result type deduction protocol.
18 The everyday Phoenix-User will encounter this change only when writing
19 [link phoenix.reference.modules.function Functions].
20
21 To make your function implementations Phoenix compliant again change from
22 the old Phoenix result type deduction protocol to the new (standard compliant)
23 result type deduction protocol:
24
25 [table
26 [[Phoenix 2.0] [Phoenix 3.0] [Notes]]
27 [
28 [``
29 struct is_odd_impl
30 {
31 template <typename Arg>
32 struct result
33 {
34 typedef bool type;
35 };
36
37 template <typename Arg>
38 bool operator()(Arg arg) const
39 {
40 return arg % 2 == 1;
41 }
42 };
43
44 boost::phoenix::function<is_odd_impl> is_odd = is_odd_impl();
45 ``]
46 [``
47 struct is_odd_impl
48 {
49 typedef bool result_type;
50
51 template <typename Arg>
52 bool operator()(Arg arg) const
53 {
54 return arg % 2 == 1;
55 }
56 };
57
58 boost::phoenix::function<is_odd_impl> is_odd = is_odd_impl();
59 ``]
60 [ __note__
61 The result_of protocol is particularly easy when you implement a monomorphic
62 function (return type not dependent on the arguments). You then just need a
63 single nested return_type typedef.
64 ]
65 ]
66 [
67 [``
68 struct add_impl
69 {
70 template <typename Arg1, typename Arg2>
71 struct result
72 {
73 typedef Arg1 type;
74 };
75
76 template <typename Arg1, typename Arg2>
77 Arg1 operator()(Arg1 arg1, Arg2 arg2) const
78 {
79 return arg1 + arg2;
80 }
81 };
82
83 boost::phoenix::function<add_impl> add = add_impl();
84 ``]
85 [``
86 struct add_impl
87 {
88 template <typename Sig>
89 struct result;
90
91 template <typename This, typename Arg1, typename Arg2>
92 struct result<This(Arg1, Arg2)>
93 : boost::remove_reference<Arg1> {};
94
95 template <typename Arg1, typename Arg2>
96 typename boost::remove_reference<Arg1>::type
97 operator()(Arg1 arg1, Arg2 arg2) const
98 {
99 return arg1 + arg2;
100 }
101 };
102
103 boost::phoenix::function<add_impl> add = add_impl();
104 ``]
105 [__alert__ When dealing with polymorphic functions the template arguments can
106 be any type including cv-qualifiers and references. For that reason, the calculated
107 result type need to remove the reference whenever appropriate!]
108 ]
109 ]
110
111 [blurb __tip__ There is no general guideline for porting code which relies on the
112 internals of Phoenix 2.0. If you plan on porting your Phoenix 2.0 extensions
113 please refer to the next sections.]
114
115 [endsect]