![]() |
Home | Libraries | People | FAQ | More |
boost::proto::pack — To turn an expression into a pseudo-parameter pack containing the expression's children, for the purpose of expanding the pack expression within a CallableTransform or ObjectTransform.
// In header: <boost/proto/transform/impl.hpp> struct pack { };
proto::pack
is useful within
CallableTransforms and
ObjectTransforms when one wishes to unpack an expression
into a function call or an object constructor. proto::pack
turns a Proto expression into a pseudo-parameter pack, which may appear in an unpacking
pattern to be expanded with the "...
" syntax.
Example:
// The following demonstrates how to use a pseudo-pack expansion // to unpack an expression into a function call. proto::callable { proto::when< // Match any nary expression where the children are all int terminals proto::nary_expr<_, proto::vararg<proto::terminal<proto::_value(_))...) > {}; proto::terminal<
The above program displays:
Sum of 42, 3, and 5 : 50
In the above example, the type
proto::_value(proto::pack(_))
is a so-called unpacking pattern, described below.
Unpacking Patterns:
Composite transforms (either CallableTransforms or
ObjectTransforms) usually have the form
X(A0,…An)
.
However, when the argument list in a composite transform is terminated with a C-style
vararg ellipsis as in X(A0,…An ...)
,
the final argument An
is treated
as an unpacking pattern.
An unpacking pattern must itself be a composite transform; that is, it must be a
function type representing either a CallableTransform or
an ObjectTransform. The type proto::pack(_)
must appear exactly once in the unpacking pattern. This type will receive a substitution
when the unpacking pattern is expanded.
A composite transform like X(A0,…An ...)
,
when evaluated against a given expression E
, state and data, is evaluated as if it were
X(A0,…An-1,
where S
)S
is a type sequence computed as follows:
Let
be a type function that replaces every occurence of
SUB
(A,B)proto::pack(_)
within A
with B
.
E
is a terminal (i.e. it has arity 0), S
is the one-element sequence containing SUB
(An, proto::_value)
.
E
is a non-terminal, S
is the sequence
SUB
(An, proto::_child_c<0>),…
SUB
(An, proto::_child_c<M
-1>)
, where
M
is the arity of the expression E
.