1<?xml version="1.0" encoding="utf-8"?> 2<!-- 3 Copyright 2012 Eric Niebler 4 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) 8 --> 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"> 14 <template> 15 <template-type-parameter name="Expr"/> 16 <template-type-parameter name="Context"/> 17 </template> 18 <purpose> 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 22 node. 23 </purpose> 24 <description> 25 <para> 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>.) 31 </para> 32 <para> 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. 36 </para> 37 </description> 38 <typedef name="Tag"> 39 <purpose>For exposition only</purpose> 40 <type>typename Expr::tag_type</type> 41 </typedef> 42 <data-member name="s_expr" specifiers="static"> 43 <purpose>For exposition only</purpose> 44 <type>Expr &</type> 45 </data-member> 46 <data-member name="s_context" specifiers="static"> 47 <purpose>For exposition only</purpose> 48 <type>Context &</type> 49 </data-member> 50 <typedef name="result_type"> 51 <type><emphasis>see-below</emphasis></type> 52 <description> 53 <itemizedlist> 54 <listitem> 55 <para> 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) 60)</programlisting> 61 </para> 62 </listitem> 63 <listitem> 64 <para> 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 69)</programlisting> 70 </para> 71 </listitem> 72 <listitem> 73 <para> 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) 79)</programlisting> 80 </para> 81 </listitem> 82 <listitem> 83 <para> 84 If <computeroutput>Tag</computeroutput> is <computeroutput> 85 <classname>proto::tag::subscript</classname> 86 </computeroutput>, 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) ] 91)</programlisting> 92 </para> 93 </listitem> 94 <listitem> 95 <para> 96 If <computeroutput>Tag</computeroutput> is <computeroutput> 97 <classname>proto::tag::if_else_</classname> 98 </computeroutput>, 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) 104)</programlisting> 105 </para> 106 </listitem> 107 <listitem> 108 <para> 109 If <computeroutput>Tag</computeroutput> is <computeroutput> 110 <classname>proto::tag::function</classname> 111 </computeroutput>, 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), 116 ... 117 <functionname>proto::eval</functionname>(<functionname>proto::child_c</functionname><N>(s_expr), s_context) ) 118)</programlisting> 119 </para> 120 </listitem> 121 </itemizedlist> 122 </description> 123 </typedef> 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> 129 <description> 130 <para>The current expression </para> 131 </description> 132 </parameter> 133 <parameter name="context"> 134 <paramtype>Context &</paramtype> 135 <description> 136 <para>The evaluation context </para> 137 </description> 138 </parameter> 139 <description> 140 <itemizedlist> 141 <listitem> 142 <para> 143 If <computeroutput>Tag</computeroutput> corresponds to a unary prefix operator, 144 then return 145 <programlisting>OP <functionname>proto::eval</functionname>(<functionname>proto::child</functionname>(expr), context)</programlisting> 146 </para> 147 </listitem> 148 <listitem> 149 <para> 150 If <computeroutput>Tag</computeroutput> corresponds to a unary postfix operator, 151 then return 152 <programlisting><functionname>proto::eval</functionname>(<functionname>proto::child</functionname>(expr), context) OP</programlisting> 153 </para> 154 </listitem> 155 <listitem> 156 <para> 157 If <computeroutput>Tag</computeroutput> corresponds to a binary infix operator, 158 then return 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> 161 </para> 162 </listitem> 163 <listitem> 164 <para> 165 If <computeroutput>Tag</computeroutput> is <computeroutput> 166 <classname>proto::tag::subscript</classname> 167 </computeroutput>, 168 then return 169 <programlisting><functionname>proto::eval</functionname>(<functionname>proto::left</functionname>(expr), context) [ 170<functionname>proto::eval</functionname>(<functionname>proto::right</functionname>(expr), context) ]</programlisting> 171 </para> 172 </listitem> 173 <listitem> 174 <para> 175 If <computeroutput>Tag</computeroutput> is <computeroutput> 176 <classname>proto::tag::if_else_</classname> 177 </computeroutput>, 178 then return 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> 182 </para> 183 </listitem> 184 <listitem> 185 <para> 186 If <computeroutput>Tag</computeroutput> is <computeroutput> 187 <classname>proto::tag::function</classname> 188 </computeroutput>, 189 then return 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), 192... 193<functionname>proto::eval</functionname>(<functionname>proto::child_c</functionname><N>(expr), context) )</programlisting> 194 </para> 195 </listitem> 196 </itemizedlist> 197 </description> 198 </method> 199 </method-group> 200 </struct> 201 202 <struct name="default_context"> 203 <purpose>An evaluation context that gives the operators their normal C++ semantics.</purpose> 204 <description> 205 <para>An evaluation context that gives the operators their normal C++ semantics.</para> 206 </description> 207 <struct name="eval"> 208 <template> 209 <template-type-parameter name="Expr"/> 210 <template-type-parameter name="ThisContext"> 211 <default>default_context const</default> 212 </template-type-parameter> 213 </template> 214 <inherit><classname>proto::context::default_eval</classname>< Expr, ThisContext ></inherit> 215 </struct> 216 </struct> 217 </namespace> 218 </namespace> 219 </namespace> 220</header> 221