<?xml version="1.0" encoding="utf-8"?>
<header name="boost/proto/transform/make.hpp">
  <para>
    Contains definition of the
    <computeroutput>
      <classname alt="boost::proto::make">proto::make&lt;&gt;</classname>
    </computeroutput>
    and
    <computeroutput>
      <classname alt="boost::proto::protect">proto::protect&lt;&gt;</classname>
    </computeroutput>
    transforms.
  </para>
  <namespace name="boost">
    <namespace name="proto">
      <struct name="protect">
        <template>
          <template-type-parameter name="PrimitiveTransform"/>
        </template>
        <inherit><classname>proto::transform</classname>&lt; protect&lt;PrimitiveTransform&gt; &gt;</inherit>
        <purpose>A <conceptname>PrimitiveTransform</conceptname> which prevents another
          <conceptname>PrimitiveTransform</conceptname> from being applied in an
          <conceptname>ObjectTransform</conceptname>.</purpose>
        <description>
          <para>
            When building higher order transforms with
            <computeroutput>
              <classname alt="proto::make">proto::make&lt;&gt;</classname>
            </computeroutput> or
            <computeroutput>
              <classname alt="proto::lazy">proto::lazy&lt;&gt;</classname>
            </computeroutput>,
            you sometimes would like to build types that are parameterized with Proto transforms. In such
            lambda-style transforms, Proto will unhelpfully find all nested transforms and apply them, even
            if you don't want them to be applied. Consider the following transform, which will replace the
            <computeroutput>proto::_</computeroutput> in
            <computeroutput>Bar&lt;proto::_&gt;()</computeroutput>
            with <computeroutput>proto::terminal&lt;int&gt;::type</computeroutput>:
          </para>
          <para>
            <programlisting>template&lt;typename T&gt;
struct Bar
{};

struct Foo :
  <classname>proto::when</classname>&lt;<classname>proto::_</classname>, Bar&lt;<classname>proto::_</classname>&gt;() &gt;
{};

<classname>proto::terminal</classname>&lt;int&gt;::type i = {0};

int main() {
  Foo()(i);
  std::cout &lt;&lt; typeid(Foo()(i)).name() &lt;&lt; std::endl;
}</programlisting>
          </para>
          <para>
            If you actually wanted to default-construct an object of type
            <computeroutput>Bar&lt;proto::_&gt;</computeroutput>, you would have to protect the
            <computeroutput>_</computeroutput> to prevent it from being applied. You can
            use <computeroutput>proto::protect&lt;&gt;</computeroutput> as follows:
          </para>
          <para>
            <programlisting>// OK: replace anything with Bar&lt;_&gt;()
struct Foo :
  <classname>proto::when</classname>&lt;<classname>proto::_</classname>, Bar&lt;<classname>proto::protect</classname>&lt;<classname>proto::_</classname>&gt; &gt;() &gt;
{};</programlisting>
          </para>
        </description>
        <struct name="impl">
          <template>
            <template-type-parameter name=""/>
            <template-type-parameter name=""/>
            <template-type-parameter name=""/>
          </template>
          <typedef name="result_type">
            <type>PrimitiveTransform</type>
          </typedef>
        </struct>
      </struct>

      <struct name="make">
        <template>
          <template-type-parameter name="T"/>
        </template>
        
        <inherit><classname>proto::transform</classname>&lt; make&lt;T&gt; &gt;</inherit>
        
        <purpose>A <conceptname>PrimitiveTransform</conceptname> which computes a type by evaluating
          any nested transforms and then constructs an object of that type. </purpose>
        
        <description>
          <para>
            The purpose of <computeroutput>proto::make&lt;&gt;</computeroutput> is to annotate a transform as
            an <conceptname>ObjectTransform</conceptname> so that
            <computeroutput>
              <classname alt="proto::when">proto::when&lt;&gt;</classname>
            </computeroutput> knows
            how to apply it.
          </para>

          <para>
            For the full description of the behavior of the
            <computeroutput><classname alt="proto::make">proto::make&lt;&gt;</classname></computeroutput>
            transform, see the documentation for the nested
            <computeroutput><classname alt="proto::make::impl">proto::make::impl&lt;&gt;</classname></computeroutput>
            class template.
          </para>
        </description>

        <struct name="impl">
          <template>
            <template-type-parameter name="Expr"/>
            <template-type-parameter name="State"/>
            <template-type-parameter name="Data"/>
          </template>
          <inherit><classname>proto::transform_impl</classname>&lt; Expr, State, Data &gt;</inherit>
          <typedef name="result_type">
            <type><emphasis>see-below</emphasis></type>
            <description>
              <para>
                <computeroutput><classname>proto::make</classname>&lt;T&gt;::impl&lt;Expr, State, Data&gt;::result_type</computeroutput> is
                computed as follows:
              </para>

              <para>
                If <computeroutput>T</computeroutput> is an <conceptname>ObjectTransform</conceptname> of the form
                <computeroutput>
                  Object(A<subscript>0</subscript>,...A<subscript>n</subscript>)
                </computeroutput>, then let <computeroutput>O</computeroutput> be
                the return type <computeroutput>Object</computeroutput>. Otherwise, let <computeroutput>O</computeroutput>
                be <computeroutput>T</computeroutput>. The <computeroutput>result_type</computeroutput> typedef is
                then computed as follows:
              </para>
              <para>
                <itemizedlist>
                  <listitem>
                    If <computeroutput>O</computeroutput> is a template like
                    <computeroutput>
                      S&lt;X<subscript>0</subscript>,...X<subscript>n</subscript>&gt;
                    </computeroutput>, then the result type is calculated as follows:
                    <itemizedlist>
                      <listitem>
                        <para>
                          For each <computeroutput>i</computeroutput> in
                          <computeroutput>[0,n]</computeroutput>, let <computeroutput>
                            X<subscript>i</subscript>'
                          </computeroutput> be
                          <computeroutput>
                            boost::result_of&lt;<classname>proto::make</classname>&lt;X<subscript>i</subscript>&gt;(Expr, State, Data)&gt;::type
                          </computeroutput>
                          (which evaluates this procedure recursively). Note whether any substitutions took place during
                          this operation.
                        </para>
                      </listitem>
                      <listitem>
                        <para>
                          If any substitutions took place in the above step and
                          <computeroutput>
                            S&lt;X<subscript>0</subscript>',...X<subscript>n</subscript>'&gt;
                          </computeroutput> has a nested
                          <computeroutput>type</computeroutput> typedef, the result type is
                          <computeroutput>
                            S&lt;X<subscript>0</subscript>',...X<subscript>n</subscript>'&gt;::type
                          </computeroutput>.
                        </para>
                      </listitem>
                      <listitem>
                        <para>
                          Otherwise, the result type is
                          <computeroutput>
                            S&lt;X<subscript>0</subscript>',...X<subscript>n</subscript>'&gt;
                          </computeroutput>.
                        </para>
                      </listitem>
                    </itemizedlist>
                  </listitem>
                  <listitem>
                    <para>
                      Otherwise, if <computeroutput>O</computeroutput> is a <conceptname>Transform</conceptname>, then let
                      the result type be
                      <computeroutput>
                        boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>_</classname>, O&gt;(Expr, State, Data)&gt;::type
                      </computeroutput>.
                      Note that a substitution took place.
                    </para>
                  </listitem>
                  <listitem>
                    Otherwise, the result type is <computeroutput>O</computeroutput>, and note that no
                    substitution took place.
                  </listitem>
                </itemizedlist>
              </para>
              <para>
                Note that <computeroutput><classname alt="proto::when">proto::when&lt;&gt;</classname></computeroutput> is implemented
                in terms of <computeroutput><classname alt="proto::call">proto::call&lt;&gt;</classname></computeroutput>
                and <computeroutput><classname alt="proto::make">proto::make&lt;&gt;</classname></computeroutput>, so the
                above procedure is evaluated recursively.
              </para>
            </description>
          </typedef>
          <method-group name="public member functions">
            <method name="operator()" cv="const">
              <type>result_type</type>
              <parameter name="expr">
                <paramtype>typename impl::expr_param</paramtype>
              </parameter>
              <parameter name="state">
                <paramtype>typename impl::state_param</paramtype>
              </parameter>
              <parameter name="data">
                <paramtype>typename impl::data_param</paramtype>
              </parameter>
              <description>
                <para>
                  <computeroutput>
                    <classname>proto::make</classname>&lt;T&gt;::impl&lt;Expr,State,Data&gt;::operator()
                  </computeroutput>
                  behaves as follows:
                </para>
                <para>
                  <itemizedlist>
                    <listitem>
                      <para>
                        If <computeroutput>T</computeroutput> is of the form
                        <computeroutput>O(A<subscript>0</subscript>,...A<subscript>n</subscript>)</computeroutput>, then:
                      </para>
                      <itemizedlist>
                        <listitem>
                          <para>
                            If <computeroutput>
                              <classname>proto::is_aggregate</classname>&lt;result_type&gt;::value
                            </computeroutput> is <computeroutput>true</computeroutput>, then construct
                            and return an object <computeroutput>that</computeroutput> as follows:
                            <programlisting>result_type that = {
  <classname>proto::when</classname>&lt;<classname>_</classname>, A<subscript>0</subscript>&gt;()(expr, state, data),
  ...
  <classname>proto::when</classname>&lt;<classname>_</classname>, A<subscript>n</subscript>&gt;()(expr, state, data)
};</programlisting>
                          </para>
                        </listitem>
                        <listitem>
                          <para>
                            Otherwise, construct
                            and return an object <computeroutput>that</computeroutput> as follows:
                            <programlisting>result_type that(
  <classname>proto::when</classname>&lt;<classname>_</classname>, A<subscript>0</subscript>&gt;()(expr, state, data),
  ...
  <classname>proto::when</classname>&lt;<classname>_</classname>, A<subscript>n</subscript>&gt;()(expr, state, data)
);</programlisting>
                          </para>
                        </listitem>
                      </itemizedlist>
                    </listitem>
                    <listitem>
                      <para>
                        Otherwise, construct
                        and return an object <computeroutput>that</computeroutput> as follows:
                        <programlisting>result_type that = result_type();</programlisting>
                      </para>
                    </listitem>
                  </itemizedlist>
                </para>
              </description>
            </method>
          </method-group>
        </struct>
      </struct>
    </namespace>
  </namespace>
</header>
