File: fold_tree.xml

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (141 lines) | stat: -rw-r--r-- 6,674 bytes parent folder | download | duplicates (11)
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
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2012 Eric Niebler

  Distributed under the Boost
  Software License, Version 1.0. (See accompanying
  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  -->
<header name="boost/proto/transform/fold_tree.hpp">
  <para>
    Contains definition of the
    <computeroutput>
      <classname alt="boost::proto::fold_tree">proto::fold_tree&lt;&gt;</classname>
    </computeroutput> and
    <computeroutput>
      <classname alt="boost::proto::reverse_fold_tree">proto::reverse_fold_tree&lt;&gt;</classname>
    </computeroutput>
    transforms.
  </para>
  <namespace name="boost">
    <namespace name="proto">
      <struct name="fold_tree">
        <template>
          <template-type-parameter name="Sequence"/>
          <template-type-parameter name="State0"/>
          <template-type-parameter name="Fun"/>
        </template>
        <inherit><classname>proto::transform</classname>&lt; fold_tree&lt;Sequence, State0, Fun&gt; &gt;</inherit>
        <purpose>A <conceptname>PrimitiveTransform</conceptname> that recursively applies the
          <computeroutput><classname>proto::fold</classname>&lt;&gt;</computeroutput> transform to sub-trees
          that all share a common tag type.</purpose>
        <description>
          <para>
            <computeroutput>proto::fold_tree&lt;&gt;</computeroutput> is useful for flattening trees into lists;
            for example, you might use <computeroutput>proto::fold_tree&lt;&gt;</computeroutput> to flatten an
            expression tree like <computeroutput>a | b | c</computeroutput> into a Fusion list like
            <computeroutput>cons(c, cons(b, cons(a)))</computeroutput>.
          </para>
          <para>
            <computeroutput>proto::fold_tree&lt;&gt;</computeroutput> is easily understood in terms of a
            <computeroutput>recurse_if_&lt;&gt;</computeroutput> helper, defined as follows:
            <programlisting> template&lt;typename Tag, typename Fun&gt;
struct recurse_if_ :
  <classname>proto::if_</classname>&lt;
    // If the current node has type type "Tag" ...
    boost::is_same&lt;<classname>proto::tag_of</classname>&lt;<classname>proto::_</classname>&gt;, Tag&gt;(),
    // ... recurse, otherwise ...
    <classname>proto::fold</classname>&lt;<classname>proto::_</classname>, <classname>proto::_state</classname>, recurse_if_&lt;Tag, Fun&gt; &gt;,
    // ... apply the Fun transform.
    Fun
  &gt;
{};</programlisting>
          </para>
          <para>
            With <computeroutput>recurse_if_&lt;&gt;</computeroutput> as defined above,
            <computeroutput>proto::fold_tree&lt;Sequence, State0, Fun&gt;()(expr, state, data)</computeroutput>
            is equivalent to:
            <programlisting><classname>proto::fold</classname>&lt;
  Sequence,
  State0,
  recurse_if_&lt;typename Expr::proto_tag, Fun&gt;
&gt;()(expr, state, data).</programlisting>
            It has the effect of folding a tree front-to-back, recursing into child nodes that share a
            tag type with the parent node.
          </para>
        </description>
        <struct name="impl">
          <template>
            <template-type-parameter name="Expr"/>
            <template-type-parameter name="State"/>
            <template-type-parameter name="Data"/>
          </template>
          <inherit>
            <type>
    <classname>proto::fold</classname>&lt;Sequence, State0, recurse_if_&lt;typename Expr::proto_tag, Fun&gt; &gt;
      ::template impl&lt;Expr, State, Data&gt;</type>
          </inherit>
        </struct>
      </struct>

      <struct name="reverse_fold_tree">
        <template>
          <template-type-parameter name="Sequence"/>
          <template-type-parameter name="State0"/>
          <template-type-parameter name="Fun"/>
        </template>
        <inherit><classname>proto::transform</classname>&lt; reverse_fold_tree&lt;Sequence, State0, Fun&gt; &gt;</inherit>
        <purpose>A <conceptname>PrimitiveTransform</conceptname> that recursively applies the 
          <computeroutput><classname>proto::reverse_fold&lt;&gt;</classname></computeroutput> transform to
          sub-trees that all share a common tag type.</purpose>
        <description>
          <para>
            <computeroutput>proto::reverse_fold_tree&lt;&gt;</computeroutput> is useful for flattening trees
            into lists; for example, you might use <computeroutput>proto::reverse_fold_tree&lt;&gt;</computeroutput>
            to flatten an expression tree like <computeroutput>a | b | c</computeroutput> into a Fusion list like
            <computeroutput>cons(a, cons(b, cons(c)))</computeroutput>.
          </para>
          <para>
            <computeroutput>proto::reverse_fold_tree&lt;&gt;</computeroutput> is easily understood in terms of
            a <computeroutput>recurse_if_&lt;&gt;</computeroutput> helper, defined as follows:
            <programlisting> template&lt;typename Tag, typename Fun&gt;
struct recurse_if_ :
  <classname>proto::if_</classname>&lt;
    // If the current node has type type "Tag" ...
    boost::is_same&lt;<classname>proto::tag_of</classname>&lt;<classname>proto::_</classname>&gt;, Tag&gt;(),
    // ... recurse, otherwise ...
    <classname>proto::reverse_fold</classname>&lt;<classname>proto::_</classname>, <classname>proto::_state</classname>, recurse_if_&lt;Tag, Fun&gt; &gt;,
    // ... apply the Fun transform.
    Fun
  &gt;
{};</programlisting>
          </para>
          <para>
            With <computeroutput>recurse_if_&lt;&gt;</computeroutput> as defined above,
            <computeroutput>proto::reverse_fold_tree&lt;Sequence, State0, Fun&gt;()(expr, state, data)</computeroutput>
            is equivalent to:
            <programlisting><classname>proto::reverse_fold</classname>&lt;
  Sequence,
  State0,
  recurse_if_&lt;typename Expr::proto_tag, Fun&gt;
&gt;()(expr, state, data).</programlisting>
            It has the effect of folding a tree back-to-front, recursing into child nodes that share a
            tag type with the parent node.
          </para>
        </description>
        <struct name="impl">
          <template>
            <template-type-parameter name="Expr"/>
            <template-type-parameter name="State"/>
            <template-type-parameter name="Data"/>
          </template>
          <inherit>
            <type>
    <classname>proto::reverse_fold</classname>&lt;Sequence, State0, recurse_if_&lt;typename Expr::proto_tag, Fun&gt; &gt;
      ::template impl&lt;Expr, State, Data&gt;</type>
          </inherit>
        </struct>
      </struct>
    </namespace>
  </namespace>
</header>