<?xml version="1.0" encoding="utf-8"?>
<header name="boost/proto/transform/make.hpp">
  <para>Contains definition of the make&lt;&gt; transform. </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 :
  proto::when&lt;_, Bar&lt;_&gt;() &gt;
{};

proto::terminal&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;_&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 :
  proto::when&lt;_, Bar&lt;protect&lt;_&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>proto::make&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(T0,...TN)</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:
                <itemizedlist>
                  <listitem>
                    If <computeroutput>O</computeroutput> is a template like
                    <computeroutput>S&lt;X0,...XN&gt;</computeroutput>, then the result type is calculated as follows:
                    <itemizedlist>
                      <listitem>
                        <para>
                          For each <computeroutput>X</computeroutput> in
                          <computeroutput>X0,...XN</computeroutput>, let <computeroutput>X'</computeroutput> be
                          <computeroutput>
                            <classname>proto::make</classname>&lt;X&gt;::impl&lt;Expr, State, Data&gt;::result_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;X0',...XN'&gt;</computeroutput> has a nested
                          <computeroutput>type</computeroutput> typedef, the result type is
                          <computeroutput>S&lt;X0',...XN'&gt;::type</computeroutput>.
                        </para>
                      </listitem>
                      <listitem>
                        <para>
                          Otherwise, the result type is
                          <computeroutput>S&lt;X0',...XN'&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>
                        <classname>when</classname>&lt;<classname>_</classname>, O&gt;::impl&lt;Expr, State, Data&gt;::result_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>
                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>proto::make&lt;T&gt;::impl&lt;Expr,State,Data&gt;::operator()</computeroutput> behaves as follows:
                  <itemizedlist>
                    <listitem>
                      <para>
                        If <computeroutput>T</computeroutput> if of the form
                        <computeroutput>O(T0,...TN)</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 = {
  proto::when&lt;_, T0&gt;()(expr, state, data),
  ...
  proto::when&lt;_, TN&gt;()(expr, state, data)
};</programlisting>
                          </para>
                        </listitem>
                        <listitem>
                          <para>
                            Otherwise, construct
                            and return an object <computeroutput>that</computeroutput> as follows:
                            <programlisting>result_type that(
  proto::when&lt;_, T0&gt;()(expr, state, data),
  ...
  proto::when&lt;_, TN&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>
