Contains definition of the proto::domain<>
class template and helpers for defining domains with a generator for customizing expression
construction and a grammar for controlling operator overloading.
proto::default_generator
proto::_
unspecified
Generator
For use in defining domain tags to be used with
proto::extends<>,
BOOST_PROTO_EXTENDS() and
BOOST_PROTO_DEFINE_OPERATORS().
A domain associates an expression type with a generator,
and optionally a grammar. It may also have a super-domain. Expressions
in a sub-domain are interoperable (i.e. can be combined freely with) expressions in a
super-domain. Finally, domains control how non-Proto objects are turned into Proto
expressions and how they are combined to form larger Proto expressions.
The Generator parameter determines how new expressions in the domain are post-processed. Typically, a generator
wraps all new expressions in a wrapper that imparts domain-specific behaviors to expressions within
its domain. (See proto::extends<>.)
The Grammar parameter determines whether a given expression is valid within the domain, and automatically
disables any operator overloads which would cause an invalid expression to be created. By default,
the Grammar parameter defaults to the wildcard, proto::_
, which makes all expressions valid within the domain.
The Super parameter declares the domain currently being defined to be a sub-domain of Super. An expression in
a sub-domain can be freely combined with expressions in its super-domain (and its
super-domain, etc.).
Example: template<typename Expr>
struct MyExpr;
struct MyGrammar
: proto::or_< proto::terminal<_>, proto::plus<MyGrammar, MyGrammar> >
{};
// Define MyDomain, in which all expressions are
// wrapped in MyExpr<> and only expressions that
// conform to MyGrammar are allowed.
struct MyDomain
: proto::domain<proto::generator<MyExpr>, MyGrammar>
{};
// Use MyDomain to define MyExpr
template<typename Expr>
struct MyExpr
: proto::extends<Expr, MyExpr<Expr>, MyDomain>
{
// ...
};
The domain::as_expr<> and
domain::as_child<> member
templates define how non-Proto objects are turned into Proto terminals and how Proto
expressions should be processed before they are combined to form larger expressions.
They can be overridden in a derived domain for customization. See their descriptions to
understand how Proto uses these two templates and what their default behavior is.
Grammar
Generator
Super
proto::callable
A callable unary MonomorphicFunctionObject that specifies how objects are turned into
Proto expressions in this domain. The resulting expression object is suitable for storage
in a local variable.
A unary MonomorphicFunctionObject that specifies how objects are turned into Proto
expressions in this domain. The resulting expression object is suitable for storage
in a local variable. In that scenario, it is usually preferable to return
expressions by value; and, in the case of objects that are not yet Proto expressions,
to wrap them by value (if possible) in a new Proto terminal expression. (Contrast
this description with the description for
proto::domain::as_child.)
The as_expr function object turns objects into
Proto expressions, if they are not already, by making them Proto terminals held by
value if possible. Objects that are already Proto expressions are simply returned
by value. If
wants_basic_expr<Generator>::value is true,
then let E be
proto::basic_expr;
otherwise, let E be
proto::expr.
Given an lvalue t of type
T:
If T is not a Proto expression type, the resulting
terminal is calculated as follows:
If T is a function type, an abstract type, or
a type derived from std::ios_base, let
A be T &.
Otherwise, let A be the type
T stripped of cv-qualifiers.
Then, the result of as_expr<T>()(t) is
Generator()(E<tag::terminal,
term< A > >::make(t)).
Otherwise, the result is t converted to an
(un-const) rvalue.
see-below
result_type
T &
The object to wrap.
proto::callable
A callable unary MonomorphicFunctionObject that specifies how objects are turned into
Proto expressions in this domain, for use in scenarios where the resulting expression is
intended to be made a child of another expression.
A unary MonomorphicFunctionObject that specifies how objects are turned into Proto
expressions in this domain. The resulting expression object is suitable for storage
as a child of another expression. In that scenario, it is usually
preferable to store child expressions by reference; or, in the case of objects that
are not yet Proto expressions, to wrap them by reference in a new Proto terminal
expression. (Contrast this description with the description for
proto::domain::as_expr.)
The as_child function object turns objects into
Proto expressions, if they are not already, by making them Proto terminals held by
reference. Objects that are already Proto expressions are simply returned by
reference. If
wants_basic_expr<Generator>::value is true,
then let E be
proto::basic_expr;
otherwise, let E be
proto::expr.
Given an lvalue t of type
T:
If T is not a Proto expression type, the resulting
terminal is
Generator()(E<tag::terminal,
term< T & > >::make(t)).
Otherwise, the result is the lvalue t.
see-below
result_type
T &
The object to wrap.
proto::domain<>
The domain expressions have by default, if
proto::extends<> has not been used
to associate a domain with an expression.
proto::domain< proto::basic_default_generator >
A domain similiar in purpose to proto::default_domain, except stating
a preference for proto::basic_expr<> over proto::expr<>.
A pseudo-domain for use in functions and metafunctions that require a domain parameter.
It indicates that the domain of the parent node should be inferred from the domains of the child nodes.
When proto::deduce_domain is used as a domain — either
explicitly or implicitly by
proto::make_expr(),
proto::unpack_expr(),
or Proto's operator overloads — Proto will use the domains of the child expressions to
compute the domain of the parent. It is done in such a way that (A) expressions in domains
that share a common super-domain are interoperable, and (B) expressions that are in
the default domain (or a sub-domain thereof) are interoperable with all
expressions. The rules are as follows:
A sub-domain is stronger than its super-domain.
proto::default_domain,
proto::basic_default_domain
and all their sub-domains are weaker than all other domains.
proto::basic_default_domain
is weaker than
proto::default_domain.
For each child, define a set of domains SN
that includes the child's domain and all its super-domains.
Define a set IS that is the intersection of
all the individual sets SN that don't contain
proto::default_domain or
proto::basic_default_domain.
Define a set IW that is the intersection of
all the individual sets SN that contain
proto::default_domain or
proto::basic_default_domain.
Define a set P that is the union of
IS and
IW.
The common domain is the strongest domain in set P, with the
following caveats.
Let U be the union of all sets
SN. If the result is
proto::default_domain or
proto::basic_default_domain
and U contains an element that is not
proto::default_domain or
proto::basic_default_domain,
it is an error.
Note: the above description sounds like it would be expensive to compute at compile time.
In fact, it can all be done using C++ function overloading.
mpl::bool_< true-or-false >
A metafunction that returns mpl::true_ if the type
T is the type of a Proto domain;
mpl::false_ otherwise. If T
inherits from proto::domain<>,
is_domain<T> is mpl::true_.
A metafunction that returns the domain of a given type. If T is a Proto
expression type, it returns that expression's associated domain. If not, it returns
proto::default_domain.
domain-of-T