...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Authors: | David Abrahams
Daniel Wallin |
---|---|
Contact: | dave@boost-consulting.com, dalwan01@student.umu.se |
Organization: | Boost Consulting |
Date: | 2005-07-17 |
Copyright: | Copyright David Abrahams, Daniel Wallin 2005. 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) |
Contents
This section covers some basic information you'll need to know in order to understand this reference
In this document, all unqualified identifiers should be assumed to be defined in namespace boost::parameter unless otherwise specified.
No operation described in this document throws an exception unless otherwise specified.
All components of this library can be used safely from multiple threads without synchronization.1
Names written in sans serif type represent concepts.
In code blocks, italic type represents unspecified text that satisfies the requirements given in the detailed description that follows the code block.
In a specification of the tokens generated by a macro, bold type is used to highlight the position of the expanded macro argument in the result.
The special character β represents the value of BOOST_PARAMETER_MAX_ARITY.
An object whose type is associated with a keyword tag type (the object's keyword), and that holds a reference (to the object's value).
As a shorthand, a “tagged reference to x” means a tagged reference whose value is x.
Note
In this reference, we will use concept names (and other names) to describe both types and objects, depending on context. So for example, “an ArgumentPack” can refer to a type that models ArgumentPack or an object of such a type.
This section describes the generic type concepts used by the Parameter library.
An ArgumentPack is a collection of tagged references to the actual arguments passed to a function. Every ArgumentPack is also a valid MPL Forward Sequence consisting of the keyword tag types in its tagged references.
In the table below,
Any exceptions are thrown from the invocation of w's value will be propagated to the caller.
Expression | Type | Requirements | Semantics/Notes |
---|---|---|---|
x[u] | binding<A,K>::type | x contains an element b whose keyword is K | Returns b's value (by reference). |
x[u] | binding<A,L,D>::type | none | If x contains an element b whose keyword is the same as u's, returns b's value (by reference). Otherwise, returns u's value. |
x[w] | lazy_binding<A,M,E>::type | none | If x contains an element b whose keyword is the same as w's, returns b's value (by reference). Otherwise, invokes w's value and returns the result. |
x, z | Model of ArgumentPack | none | Returns an ArgumentPack containing all the elements of both x and z. |
A ParameterSpec describes the type requirements for arguments corresponding to a given keyword and indicates whether the argument is optional or required. The table below details the allowed forms and describes their condition for satisfaction by an actual argument type. In each row,
Type | A required | Condition A must satisfy |
---|---|---|
K | no | n/a |
optional<K,F> | no | mpl::apply<F,A>::type::value is true. |
required<K,F> | yes | mpl::apply<F,A>::type::value is true. |
The information in a ParameterSpec is used to limit the arguments that will be matched by forwarding functions.
The type of every keyword object is a specialization of keyword.
Defined in: | boost/parameter/keyword.hpp |
---|
template <class Tag> struct keyword { template <class T> ArgumentPack operator=(T& value) const; template <class T> ArgumentPack operator=(T const& value) const; template <class T> tagged default operator|(T& x) const; template <class T> tagged default operator|(T const& x) const; template <class F> tagged lazy default operator||(F const&) const; static keyword<Tag>& get(); };
template <class T> ArgumentPack operator=(T& value) const; template <class T> ArgumentPack operator=(T const& value) const;
Requires: | nothing |
---|---|
Returns: | an ArgumentPack containing a single tagged reference to value with keyword Tag |
template <class T> tagged default operator|(T& x) const; template <class T> tagged default operator|(T const& x) const;
Returns: | a tagged default with value x and keyword Tag. |
---|
template <class F> tagged lazy default operator||(F const& g) const;
Requires: | g() is valid, with type boost::result_of<F()>::type.2 |
---|---|
Returns: | a tagged lazy default with value g and keyword Tag. |
static keyword<Tag>& get();
Returns: | a “singleton instance”: the same object will be returned on each invocation of get(). |
---|---|
Thread Safety: | get() can be called from multiple threads simultaneously. |
Provides an interface for assembling the actual arguments to a forwarding function into an ArgumentPack, in which any positional arguments will be tagged according to the corresponding template argument to parameters.
Defined in: | boost/parameter/parameters.hpp |
---|
template <class P0 = unspecified, class P1 = unspecified, …class Pβ = unspecified> struct parameters { template <class A0, class A1 = unspecified, …class Aβ = unspecified> struct match { typedef … type; }; template <class A0> ArgumentPack operator()(A0& a0) const; template <class A0, class A1> ArgumentPack operator()(A0& a0, A1& a1) const; ⋮ template <class A0, class A1, …class Aβ> ArgumentPack operator()(A0& a0, A1& a1, …Aβ& aβ) const; };
Requires: | P0, P1, … Pβ are models of ParameterSpec. |
---|
Note
In this section, Ri and Ki are defined as follows, for any argument type Ai:
let D0 the set [d0, …, dj] of all deduced parameter specs in [P0, …, Pβ]thenKi is Telseor some Pj in j≤i is deducedthenelse
A Metafunction used to remove a forwarding function from overload resolution.
Returns: | if P0, P1, …Pβ are satisfied (see below), then parameters<P0,P1,…Pβ>. Otherwise, match<A0,A1,…Aβ>::type is not defined. |
---|
P0, P1, …Pβ are satisfied if, for every j in 0…β, either:
template <class A0> ArgumentPack operator()(A0 const& a0) const; ⋮ template <class A0, …class Aβ> ArgumentPack operator()(A0 const& a0, …Aβ const& aβ) const;
Returns: | An ArgumentPack containing, for each ai,
|
---|
These templates describe the requirements on a function parameter.
Defined in: | boost/parameter/parameters.hpp |
---|
Specializations model: | |
---|---|
ParameterSpec |
template <class Tag, class Predicate = unspecified> struct optional; template <class Tag, class Predicate = unspecified> struct required;
The default value of Predicate is an unspecified Metafunction that returns mpl::true_ for any argument.
This template is used to wrap the keyword tag argument to optional or required.
Defined in: | boost/parameter/parameters.hpp |
---|
template <class Tag> struct deduced;
A Metafunction is conceptually a function that operates on, and returns, C++ types.
Returns the result type of indexing an argument pack with a keyword tag type or with a tagged default.
Defined n: | boost/parameter/binding.hpp |
---|
template <class A, class K, class D = void> struct binding { typedef … type; };
Requires: | A is a model of ArgumentPack. |
---|---|
Returns: | the reference type of the tagged reference in A having keyword tag type K, if any. If no such tagged reference exists, returns D. |
Returns the result type of indexing an argument pack with a tagged lazy default.
Defined in: | boost/parameter/binding.hpp |
---|
template <class A, class K, class F> struct lazy_binding { typedef … type; };
Requires: | A is a model of ArgumentPack. |
---|---|
Returns: | the reference type of the tagged reference in A having keyword tag type K, if any. If no such tagged reference exists, returns boost::result_of<F()>::type.2 |
Returns the result type of indexing an argument pack with a keyword tag type or with a tagged default.
Defined n: | boost/parameter/value_type.hpp |
---|
template <class A, class K, class D = void> struct value_type { typedef … type; };
Requires: | A is a model of ArgumentPack. |
---|---|
Returns: | the type of the tagged reference in A having keyword tag type K, if any. If no such tagged reference exists, returns D. Equivalent to: typename remove_reference< typename binding<A, K, D>::type >::type … when D is not a reference type. |
Macros in this section can be used to ease the writing of code using the Parameter libray by eliminating repetitive boilerplate.
Defined in: | boost/parameter/preprocessor.hpp |
---|
Requires: | result is the parenthesized return type of the function. name is the base name of the function, this is the name of the generated forwarding functions. tag_namespace is the namespace in which the keywords used by the function resides. arguments is a list of argument specifiers, as defined below. |
---|---|
Argument specifiers syntax: | |
argument-specifiers ::= specifier-group {specifier-group} specifier-group0 ::= specifier-group1 | ( '(' 'deduced' specifier-group1 {specifier-group1} ')' ) specifier-group1 ::= ( '(' 'optional' optional-specifier {optional-specifier} ')' ) | ( '(' 'required' required-specifier {required-specifier} ')' ) optional-specifier ::= '(' name ',' restriction ',' default-value ')' required-specifier ::= '(' name ',' restriction ')' restriction ::= ('*' '(' lambda-expression ')' ) | ( '(' typename ')' ) | '*' name is any valid C++ identifier. default-value is any valid C++ expression. typename is the name of a type. lambda-expression is an MPL lambda expression. |
Generated names in enclosing scope: | |
---|---|
|
Where:
template <class T>
struct boost_param_result_ ## __LINE__ ## name
{
typedef result type;
};
struct boost_param_params_ ## __LINE__ ## name
: boost::parameter::parameters<
list of parameter specifications, based on arguments
>
{};
typedef boost_param_params_ ## __LINE__ ## name
boost_param_parameters_ ## __LINE__ ## name;
template <class A0, …, class An>
result type name(
A0 cv& a0, …, An cv& an
, typename boost_param_parameters_ ## __LINE__ ## name::match<
A0 cv, …, An cv
>::type = boost_param_parameters_ ## __LINE__ ## name()
)
{
… forward to implementation …
}
⋮
template <class A0, …, class Am>
result type name(
A0 cv& a0, …, Am cv& am
, typename boost_param_parameters_ ## __LINE__ ## name::match<
A0 cv, …, Am cv
>::type = boost_param_parameters_ ## __LINE__ ## name()
)
{
… forward to implementation …
}
template <
class ResultType
, class argument name0 ## _type
…
, class argument namem ## _type
>
ResultType boost_param_default_ ## __LINE__ ## name(
(ResultType(*)())
, argument name0 ## _type& argument name0
…
, argument namem ## _type& argument namem
)
Defined in: | boost/parameter/preprocessor.hpp |
---|
See BOOST_PARAMETER_FUNCTION(result,name,tag_namespace,arguments)
Defined in: | boost/parameter/preprocessor.hpp |
---|
Requires: | cls is the name of this class. impl is the parenthesized implementation base class for cls. tag_namespace is the namespace in which the keywords used by the function resides. arguments is a list of argument specifiers, as defined in BOOST_PARAMETER_FUNCTION(result,name,tag_namespace,arguments). |
---|---|
Generated names in enclosing scope: | |
|
Where:
struct boost_param_params_ ## __LINE__ ## ctor
: boost::parameter::parameters<
list of parameter specifications, based on arguments
>
{};
typedef boost_param_params_ ## __LINE__ ## name
constructor_parameters ## __LINE__;
template <class A0, …, class An>
cls(A0 const& a0, …, An const& an)
: impl(constructor_parameters ## __LINE__(a0, …, an))
{}
⋮
template <class A0, …, class Am>
cls(A0 const& a0, …, An const& am)
: impl(constructor_parameters ## __LINE__(a0, …, am))
{}
Declares a tag-type and keyword object.
Expands to:
If name is of the form:
(tag-name, namespace-name) object-name
then
namespace namespace-name { struct tag-name { static char const* keyword_name() { return ##tag-name; } typedef implementation defined _; typedef implementation defined _1; }; } ::boost::parameter::keyword<tag-namespace::tag-name> const& object-name = ::boost::parameter::keyword<tag-namespace::tag-name>::instance;
Else
namespace tag { struct name { static char const* keyword_name() { return ##name; } typedef implementation defined _; typedef implementation defined _1; }; } ::boost::parameter::keyword<tag::name> const& _name = ::boost::parameter::keyword<tag::name>::instance;
Expands to:
namespace tag { struct name; } template <class T> struct name : ::boost::parameter::template_keyword<tag::name, T> {};
Deprecated
This macro has been deprecated in favor of BOOST_PARAMETER_FUNCTION.
Generates a sequence of forwarding function templates named n, with arities ranging from l to h , returning r, and using p to control overload resolution and assign tags to positional arguments.
Defined in: | boost/parameter/macros.hpp |
---|
Requires: | l and h are nonnegative integer tokens such that l < h |
---|
template <class A1, class A2, …class A##l> r name( A1 const& a1, A2 const& a2, …Al const& xl , typename p::match<A1,A2,…Al>::type p = p()) { return name_with_named_params(p(x1,x2,…xl)); } template <class A1, class A2, …class Al, class A##BOOST_PP_INC(l)> r name( A1 const& a1, A2 const& a2, …Al const& xl , A##BOOST_PP_INC(l) const& x##BOOST_PP_INC(l) , typename p::match<A1,A2,…Al,A##BOOST_PP_INC(l)>::type p = p()) { return name_with_named_params(p(x1,x2,…xl,x##BOOST_PP_INC(l))); } ⋮ template <class A1, class A2, …class Ah> r name( A1 const& a1, A2 const& a2, …Ah const& xh , typename p::match<A1,A2,…Ah>::type p = p()) { return name_with_named_params(p(a1,a2,…ah)); }
Deprecated
This macro has been deprecated in favor of BOOST_PARAMETER_NAME.
Generates the declaration of a keyword tag type named k in namespace n, and a corresponding keyword object definition in the enclosing namespace.
Defined in: | boost/parameter/keyword.hpp |
---|
namespace n { struct k; } namespace { boost::parameter::keyword<tag-namespace::k>& k = boost::parameter::keyword<tag-namespace::k>::get(); }
Generates a defaulted parameter declaration for a forwarding function.
Defined in: | boost/parameter/match.hpp |
---|
Requires: | a is a Boost.Preprocessor sequence of the form (A0)(A1)…(An) |
---|
typename p::match<A0,A1…,An>::type x = p()
Determines the maximum number of arguments supported by the library. Will only be #defined by the library if it is not already #defined.
Defined in: | boost/parameter/config.hpp |
---|
Default Value: | 5 |
---|
Follow this link to the Boost.Parameter tutorial documentation.
[1] | References to tag objects may be initialized multiple times. This scenario can only occur in the presence of threading. Because the C++ standard doesn't consider threading, it doesn't explicitly allow or forbid multiple initialization of references. That said, it's hard to imagine an implementation where it could make a difference. |
[2] | (1, 2) Where BOOST_NO_RESULT_OF is #defined, boost::result_of<F()>::type is replaced by F::result_type. |