Authors: | David Abrahams, Daniel Wallin |
---|---|
Contact: | dave@boost-consulting.com, dalwan01@student.umu.se |
organization: | Boost Consulting |
date: | $Date: 2005/07/17 19:53:01 $ |
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) |
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.
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 |
---|---|---|
keyword<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 const& a0) const; template <class A0, class A1> ArgumentPack operator()(A0 const& a0, A1 const& a1) const; . . . template <class A0, class A1, …class Aβ> ArgumentPack operator()(A0 const& a0, A1 const& a1, …Aβ const& 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:
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.
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 |
Macros in this section can be used to ease the writing of code using the Parameter libray by eliminating repetitive boilerplate.
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)); }
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. |