1 <?xml version=
"1.0" encoding=
"utf-8"?>
3 Copyright 2012 Eric Niebler
5 Distributed under the Boost
6 Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 <header name=
"boost/proto/context/default.hpp">
10 <namespace name=
"boost">
11 <namespace name=
"proto">
12 <namespace name=
"context">
13 <struct name=
"default_eval">
15 <template-type-parameter name=
"Expr"/>
16 <template-type-parameter name=
"Context"/>
19 A BinaryFunction that accepts a Proto expression and a context, evaluates
20 each child expression with the context, and combines the result using the
21 standard C++ meaning for the operator represented by the current expression
26 Let
<computeroutput><computeroutput>OP
</computeroutput></computeroutput> be the C++ operator
27 corresponding to
<computeroutput>Expr::proto_tag
</computeroutput>. (For example, if
28 <computeroutput>Tag
</computeroutput> is
<computeroutput>
29 <classname>proto::tag::plus
</classname></computeroutput>, let
<computeroutput>
30 <computeroutput>OP
</computeroutput></computeroutput> be
<computeroutput>+
</computeroutput>.)
33 The behavior of this class is specified in terms of the C++
0x
<computeroutput>decltype
</computeroutput>
34 keyword. In systems where this keyword is not available, Proto uses the Boost.Typeof library to
35 approximate the behavior.
39 <purpose>For exposition only
</purpose>
40 <type>typename Expr::tag_type
</type>
42 <data-member name=
"s_expr" specifiers=
"static">
43 <purpose>For exposition only
</purpose>
44 <type>Expr
&</type>
46 <data-member name=
"s_context" specifiers=
"static">
47 <purpose>For exposition only
</purpose>
48 <type>Context
&</type>
50 <typedef name=
"result_type">
51 <type><emphasis>see-below
</emphasis></type>
56 If
<computeroutput>Tag
</computeroutput> corresponds to a unary prefix operator,
57 then the result type is
58 <programlisting>decltype(
59 OP
<functionname>proto::eval
</functionname>(
<functionname>proto::child
</functionname>(s_expr), s_context)
65 If
<computeroutput>Tag
</computeroutput> corresponds to a unary postfix operator,
66 then the result type is
67 <programlisting>decltype(
68 <functionname>proto::eval
</functionname>(
<functionname>proto::child
</functionname>(s_expr), s_context) OP
74 If
<computeroutput>Tag
</computeroutput> corresponds to a binary infix operator,
75 then the result type is
76 <programlisting>decltype(
77 <functionname>proto::eval
</functionname>(
<functionname>proto::left
</functionname>(s_expr), s_context) OP
78 <functionname>proto::eval
</functionname>(
<functionname>proto::right
</functionname>(s_expr), s_context)
84 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
85 <classname>proto::tag::subscript
</classname>
87 then the result type is
88 <programlisting>decltype(
89 <functionname>proto::eval
</functionname>(
<functionname>proto::left
</functionname>(s_expr), s_context) [
90 <functionname>proto::eval
</functionname>(
<functionname>proto::right
</functionname>(s_expr), s_context) ]
96 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
97 <classname>proto::tag::if_else_
</classname>
99 then the result type is
100 <programlisting>decltype(
101 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><0>(s_expr), s_context) ?
102 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><1>(s_expr), s_context) :
103 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><2>(s_expr), s_context)
109 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
110 <classname>proto::tag::function
</classname>
112 then the result type is
113 <programlisting>decltype(
114 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><0>(s_expr), s_context) (
115 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><1>(s_expr), s_context),
117 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><N
>(s_expr), s_context) )
124 <method-group name=
"public member functions">
125 <method name=
"operator()" cv=
"const">
126 <type>result_type
</type>
127 <parameter name=
"expr">
128 <paramtype>Expr
&</paramtype>
130 <para>The current expression
</para>
133 <parameter name=
"context">
134 <paramtype>Context
&</paramtype>
136 <para>The evaluation context
</para>
143 If
<computeroutput>Tag
</computeroutput> corresponds to a unary prefix operator,
145 <programlisting>OP
<functionname>proto::eval
</functionname>(
<functionname>proto::child
</functionname>(expr), context)
</programlisting>
150 If
<computeroutput>Tag
</computeroutput> corresponds to a unary postfix operator,
152 <programlisting><functionname>proto::eval
</functionname>(
<functionname>proto::child
</functionname>(expr), context) OP
</programlisting>
157 If
<computeroutput>Tag
</computeroutput> corresponds to a binary infix operator,
159 <programlisting><functionname>proto::eval
</functionname>(
<functionname>proto::left
</functionname>(expr), context) OP
160 <functionname>proto::eval
</functionname>(
<functionname>proto::right
</functionname>(expr), context)
</programlisting>
165 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
166 <classname>proto::tag::subscript
</classname>
169 <programlisting><functionname>proto::eval
</functionname>(
<functionname>proto::left
</functionname>(expr), context) [
170 <functionname>proto::eval
</functionname>(
<functionname>proto::right
</functionname>(expr), context) ]
</programlisting>
175 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
176 <classname>proto::tag::if_else_
</classname>
179 <programlisting><functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><0>(expr), context) ?
180 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><1>(expr), context) :
181 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><2>(expr), context)
</programlisting>
186 If
<computeroutput>Tag
</computeroutput> is
<computeroutput>
187 <classname>proto::tag::function
</classname>
190 <programlisting><functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><0>(expr), context) (
191 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><1>(expr), context),
193 <functionname>proto::eval
</functionname>(
<functionname>proto::child_c
</functionname><N
>(expr), context) )
</programlisting>
202 <struct name=
"default_context">
203 <purpose>An evaluation context that gives the operators their normal C++ semantics.
</purpose>
205 <para>An evaluation context that gives the operators their normal C++ semantics.
</para>
209 <template-type-parameter name=
"Expr"/>
210 <template-type-parameter name=
"ThisContext">
211 <default>default_context const
</default>
212 </template-type-parameter>
214 <inherit><classname>proto::context::default_eval
</classname>< Expr, ThisContext
></inherit>