File: callable.xml

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (169 lines) | stat: -rw-r--r-- 8,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="utf-8"?>
<header name="boost/proto/context/callable.hpp">
  <para>Definintion of <computeroutput><classname alt="boost::proto::context::callable_context">proto::context::callable_context&lt;&gt;</classname></computeroutput>,
    an evaluation context for <computeroutput><functionname alt="boost::proto::eval">proto::eval()</functionname></computeroutput>
    that fans out each node and calls the derived context type with the expressions constituents. If the derived context
    doesn't have an overload that handles this node, fall back to some other context. </para>
  <namespace name="boost">
    <namespace name="proto">
      <namespace name="context">
        <struct name="callable_eval">
          <template>
            <template-type-parameter name="Expr"/>
            <template-type-parameter name="Context"/>
          </template>
          <purpose>A BinaryFunction that accepts a Proto expression and a callable context and calls
            the context with the expression tag and children as arguments, effectively fanning the
            expression out. </purpose>
          <description>
            <para>
              <computeroutput>proto::context::callable_eval&lt;&gt;</computeroutput> requires that
              <computeroutput>Context</computeroutput> is a <conceptname>PolymorphicFunctionObject</conceptname>
              that can be invoked with <computeroutput>Expr</computeroutput>'s tag and children as
              expressions, as follows:
              <programlisting>context(typename Expr::proto_tag(), <functionname>proto::child_c</functionname>&lt;0&gt;(expr), ... <functionname>proto::child_c</functionname>&lt;N&gt;(expr))</programlisting>
            </para>
          </description>
          <typedef name="result_type">
            <type>typename boost::result_of&lt;
    Context(
      typename Expr::proto_tag,
      typename proto::result_of::child_c&lt;0&gt;::type,
      ...
      typename proto::result_of::child_c&lt;N&gt;::type,
    )&gt;::type
  </type>
          </typedef>

          <method-group name="public member functions">
            <method name="operator()" cv="const">
              <type>result_type</type>
              <parameter name="expr">
                <paramtype>Expr &amp;</paramtype>
                <description>
                  <para>The current expression </para>
                </description>
              </parameter>
              <parameter name="context">
                <paramtype>Context &amp;</paramtype>
                <description>
                  <para>The callable evaluation context </para>
                </description>
              </parameter>
              <returns>
                <para>
                  <computeroutput>
                    context(typename Expr::proto_tag(),
                    <functionname>proto::child_c</functionname>&lt;0&gt;(expr),...
                    <functionname>proto::child_c</functionname>&lt;N&gt;(expr))
                  </computeroutput>
                </para>
              </returns>
            </method>
          </method-group>
        </struct>
        
        <struct name="callable_context">
          <template>
            <template-type-parameter name="Context"/>
            <template-type-parameter name="DefaultCtx">
              <default><classname>proto::context::default_context</classname></default>
            </template-type-parameter>
          </template>
          <purpose>An evaluation context adaptor that makes authoring a context a simple matter of
            writing function overloads, rather then writing template specializations.</purpose>
          <description>
            <para>
              <computeroutput>proto::callable_context&lt;&gt;</computeroutput> is a base class that
              implements the context protocol by passing fanned-out expression nodes to the derived
              context, making it easy to customize the handling of expression types by writing function
              overloads. Only those expression types needing special handling require explicit handling.
              All others are dispatched to a user-specified default context,
              <computeroutput>DefaultCtx</computeroutput>.
            </para>
            <para>
              <computeroutput>proto::callable_context&lt;&gt;</computeroutput> is defined simply as:
            </para>
            <para>
              <programlisting>template&lt;typename Context, typename DefaultCtx = default_context&gt;
struct callable_context {
  template&lt;typename Expr, typename ThisContext = Context&gt;
  struct eval :
    mpl::if_&lt;
      is_expr_handled_&lt;Expr, Context&gt;, // For exposition
      <classname>proto::context::callable_eval</classname>&lt;Expr, ThisContext&gt;,
      typename DefaultCtx::template eval&lt;Expr, Context&gt;
    &gt;::type
  {};
};</programlisting>
            </para>
            <para>
              The Boolean metafunction <computeroutput>is_expr_handled_&lt;&gt;</computeroutput> uses
              metaprogramming tricks to determine whether <computeroutput>Context</computeroutput> has
              an overloaded function call operator that accepts the fanned-out constituents of an
              expression of type <computeroutput>Expr</computeroutput>. If so, the handling of the
              expression is dispatched to
              <computeroutput><classname>proto::context::callable_eval&lt;&gt;</classname></computeroutput>.
              If not, it is dispatched to the user-specified <computeroutput>DefaultCtx</computeroutput>.
            </para>
            <para>
              <emphasis role="bold">Example:</emphasis>
            </para>
            <para>
              <programlisting>// An evaluation context that increments all
// integer terminals in-place.
struct increment_ints :
  <classname>proto::context::callable_context</classname>&lt;
    increment_ints const                // derived context
    <classname>proto::context::null_context</classname> const  // fall-back context
  &gt;
{
    typedef void result_type;

    // Handle int terminals here:
    void operator()(proto::tag::terminal, int &amp;i) const
    {
       ++i;
    }
};</programlisting>
            </para>
            <para>
              With <computeroutput>increment_ints</computeroutput>, we can do the following:
            </para>
            <para>
              <programlisting><classname>proto::literal</classname>&lt;int&gt; i = 0, j = 10;
proto::eval( i - j * 3.14, increment_ints() );

assert( i.get() == 1 &amp;&amp; j.get() == 11 );</programlisting>
            </para>
          </description>
          <struct name="eval">
            <template>
              <template-type-parameter name="Expr"/>
              <template-type-parameter name="ThisContext">
                <default>Context</default>
              </template-type-parameter>
            </template>
            <description>
              <para>
                A BinaryFunction that accepts an <computeroutput>Expr</computeroutput> and a
                <computeroutput>Context</computeroutput>, and either fans out the expression and passes
                it to the context, or else hands off the expression to <computeroutput>DefaultCtx</computeroutput>.
              </para>
              <para>
                If <computeroutput>Context</computeroutput> is a <conceptname>PolymorphicFunctionObject</conceptname>
                such that it can be invoked with the tag and children of <computeroutput>Expr</computeroutput>, as
                <computeroutput>ctx(typename Expr::proto_tag(), child_c&lt;0&gt;(expr),... child_c&lt;N&gt;(expr))</computeroutput>,
                then <computeroutput>eval&lt;Expr, ThisContext&gt;</computeroutput> inherits from
                <computeroutput><classname>proto::context::callable_eval</classname>&lt;Expr, ThisContext&gt;</computeroutput>.
                Otherwise, <computeroutput>eval&lt;Expr, ThisContext&gt;</computeroutput> inherits from
                <computeroutput>DefaultCtx::eval&lt;Expr, Context&gt;</computeroutput>.
              </para>
            </description>
            <inherit><type><replaceable>see-below</replaceable></type></inherit>
          </struct>
        </struct>
      </namespace>
    </namespace>
  </namespace>
</header>