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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
<?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/make.hpp">
<para>
Contains definition of the
<computeroutput>
<classname alt="boost::proto::make">proto::make<></classname>
</computeroutput>
and
<computeroutput>
<classname alt="boost::proto::protect">proto::protect<></classname>
</computeroutput>
transforms.
</para>
<namespace name="boost">
<namespace name="proto">
<struct name="noinvoke">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>A type annotation in an <conceptname>ObjectTransform</conceptname> which instructs
Proto not to look for a nested <computeroutput>::type</computeroutput> within
<computeroutput>T</computeroutput> after type substitution.</purpose>
<description>
<para>
<conceptname>ObjectTransform</conceptname>s are evaluated by
<computeroutput><classname alt="proto::make">proto::make<></classname></computeroutput>,
which finds all nested transforms and replaces them with the result of their applications.
If any substitutions are performed, the result is first assumed to be a metafunction to be applied;
that is, Proto checks to see if the result has a nested <computeroutput>::type</computeroutput>
typedef. If it does, that becomes the result. The purpose of <computeroutput>proto::noinvoke<></computeroutput>
is to prevent Proto from looking for a nested <computeroutput>::type</computeroutput> typedef
in these situations.
</para>
<para>
Example:
<programlisting>struct Test
: <classname>proto::when</classname><
<classname>_</classname>
, proto::noinvoke<
// This remove_pointer invocation is bloked by noinvoke
boost::remove_pointer<
// This add_pointer invocation is *not* blocked by noinvoke
boost::add_pointer<<classname>_</classname>>
>
>()
>
{};
void test_noinvoke()
{
typedef <classname>proto::terminal</classname><int>::type Int;
BOOST_MPL_ASSERT((
boost::is_same<
boost::result_of<Test(Int)>::type
, boost::remove_pointer<Int *>
>
));
Int i = {42};
boost::remove_pointer<Int *> t = Test()(i);
}</programlisting>
</para>
</description>
</struct>
<struct name="protect">
<template>
<template-type-parameter name="PrimitiveTransform"/>
</template>
<inherit><classname>proto::transform</classname>< protect<PrimitiveTransform> ></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<></classname>
</computeroutput> or
<computeroutput>
<classname alt="proto::lazy">proto::lazy<></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<proto::_>()</computeroutput>
with <computeroutput>proto::terminal<int>::type</computeroutput>:
</para>
<para>
<programlisting>template<typename T>
struct Bar
{};
struct Foo :
<classname>proto::when</classname><<classname>proto::_</classname>, Bar<<classname>proto::_</classname>>() >
{};
<classname>proto::terminal</classname><int>::type i = {0};
int main() {
Foo()(i);
std::cout << typeid(Foo()(i)).name() << std::endl;
}</programlisting>
</para>
<para>
If you actually wanted to default-construct an object of type
<computeroutput>Bar<proto::_></computeroutput>, you would have to protect the
<computeroutput>_</computeroutput> to prevent it from being applied. You can
use <computeroutput>proto::protect<></computeroutput> as follows:
</para>
<para>
<programlisting>// OK: replace anything with Bar<_>()
struct Foo :
<classname>proto::when</classname><<classname>proto::_</classname>, Bar<<classname>proto::protect</classname><<classname>proto::_</classname>> >() >
{};</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>< make<T> ></inherit>
<purpose>A <conceptname>PrimitiveTransform</conceptname> that 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<></computeroutput> is to annotate a transform as
an <conceptname>ObjectTransform</conceptname> so that
<computeroutput><classname alt="proto::when">proto::when<></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<></classname></computeroutput>
transform, see the documentation for the nested
<computeroutput><classname alt="proto::make::impl">proto::make::impl<></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>< Expr, State, Data ></inherit>
<typedef name="result_type">
<type><emphasis>see-below</emphasis></type>
<description>
<para>
<computeroutput><classname>proto::make</classname><T>::impl<Expr, State, Data>::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> or
<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>
<para>
If <computeroutput><classname>proto::is_transform</classname><O>::value</computeroutput> is
<computeroutput>true</computeroutput>, then let the result type be
<computeroutput>
boost::result_of<<classname>proto::when</classname><<classname>_</classname>, O>(Expr, State, Data)>::type
</computeroutput>.
Note that a substitution took place.
</para>
</listitem>
<listitem>
If <computeroutput>O</computeroutput> is a template like
<computeroutput><classname>proto::noinvoke</classname><S<X<subscript>0</subscript>,…X<subscript>n</subscript>> ></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<<classname>proto::make</classname><X<subscript>i</subscript>>(Expr, State, Data)>::type
</computeroutput>
(which evaluates this procedure recursively). Note that a substitution took place. (In this case,
Proto merely assumes that a substitution took place for the sake of compile-time efficiency. There
would be no reason to use <computeroutput><classname>proto::noinvoke<></classname></computeroutput>
otherwise.)
</para>
</listitem>
<listitem>
<para>
The result type is
<computeroutput>
S<X<subscript>0</subscript>',…X<subscript>n</subscript>'>
</computeroutput>.
</para>
</listitem>
</itemizedlist>
</listitem>
<listitem>
If <computeroutput>O</computeroutput> is a template like
<computeroutput>S<X<subscript>0</subscript>,…X<subscript>n</subscript>></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<<classname>proto::make</classname><X<subscript>i</subscript>>(Expr, State, Data)>::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<X<subscript>0</subscript>',…X<subscript>n</subscript>'>
</computeroutput> has a nested
<computeroutput>type</computeroutput> typedef, the result type is
<computeroutput>
S<X<subscript>0</subscript>',…X<subscript>n</subscript>'>::type
</computeroutput>.
</para>
</listitem>
<listitem>
<para>
Otherwise, the result type is
<computeroutput>
S<X<subscript>0</subscript>',…X<subscript>n</subscript>'>
</computeroutput>.
</para>
</listitem>
</itemizedlist>
</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<></classname></computeroutput> is implemented
in terms of <computeroutput><classname alt="proto::call">proto::call<></classname></computeroutput>
and <computeroutput><classname alt="proto::make">proto::make<></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><T>::impl<Expr,State,Data>::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><result_type>::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><<classname>_</classname>, A<subscript>0</subscript>>()(expr, state, data),
…
<classname>proto::when</classname><<classname>_</classname>, A<subscript>n</subscript>>()(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><<classname>_</classname>, A<subscript>0</subscript>>()(expr, state, data),
…
<classname>proto::when</classname><<classname>_</classname>, A<subscript>n</subscript>>()(expr, state, data)
);</programlisting>
</para>
</listitem>
</itemizedlist>
</listitem>
<listitem>
<para>
If <computeroutput>T</computeroutput> is of the form
<computeroutput>O(A<subscript>0</subscript>,…A<subscript>n</subscript> ...)</computeroutput>,
then let <computeroutput>T'</computeroutput> be <computeroutput>O(A<subscript>0</subscript>,…A<subscript>n-1</subscript>, <replaceable>S</replaceable>)</computeroutput>,
where <replaceable>S</replaceable> is a type sequence computed from the unpacking expression <computeroutput>A<subscript>n</subscript></computeroutput>
as described in the reference for <computeroutput><classname>proto::pack</classname></computeroutput>. Then, return:
<programlisting>proto::make<T'>()(expr, state, data)</programlisting>
</para>
</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>
|