Skip to content

Commit c9c0972

Browse files
committed
improve doc
1 parent fc17021 commit c9c0972

16 files changed

Lines changed: 169 additions & 98 deletions

doc/abstract_policy.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ struct abstract_policy {};
1414
### Description
1515

1616
`abstract_policy` is a required base class for a policy. It makes it possible
17-
for meta-functions such as `use_classes` to discriminate between user classes
17+
for metafunctions such as `use_classes` to discriminate between user classes
1818
and the (optional) policy class.

doc/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4924,7 +4924,7 @@ <h4 id="virtual_ptr_synopsis_6">Synopsis</h4>
49244924
<h4 id="virtual_ptr_description_6">Description</h4>
49254925
<div class="paragraph">
49264926
<p><code>abstract_policy</code> is a required base class for a policy. It makes it possible
4927-
for meta-functions such as <code>use_classes</code> to discriminate between user classes
4927+
for metafunctions such as <code>use_classes</code> to discriminate between user classes
49284928
and the (optional) policy class.</p>
49294929
</div>
49304930
</div>

doc/modules/ROOT/pages/BOOST_OPENMETHOD.adoc

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,71 @@ BOOST_OPENMETHOD(ID, (PARAMETERS...), RETURN_TYPE [, REGISTRY]);
1111

1212
### Description
1313

14-
Declares a method.
14+
Declares a method, called `ID`, with the given `PARAMETERS` and `RETURN_TYPE`,
15+
and adds it to `REGISTRY`.
1516

16-
The macro expands to several constructs:
17+
`PARAMETERS` is a comma-separated list of types, possibly followed by parameter
18+
names, just like in a function declaration. Parameters with a type in the form
19+
`virtual_ptr<T>` or `virtual_<T>` are called virtual parameters. The dynamic
20+
type of the arguments passed in virtual parameters determines which overrider to
21+
call, following the same rules as overloaded function resolution:
22+
23+
1. Form the set of all applicable overriders. An overrider is applicable
24+
if it can be called with the arguments passed to the method.
25+
2. If the set is empty, call the error handler (if present in the
26+
registry), then terminate the program with `abort`.
27+
3. Remove the overriders that are dominated by other overriders in the
28+
set. Overrider A dominates overrider B if any of its virtual formal
29+
parameters is more specialized than B's, and if none of B's virtual
30+
parameters is more specialized than A's.
31+
4. If the resulting set contains exactly one overrider, call it.
32+
33+
If a single most specialized overrider does not exist, the program is
34+
terminated via `abort`. If the registry contains an `error_handler`
35+
policy, its `error` function is called with an object that describes the
36+
error, prior calling `abort`. `error` may prevent termination by throwing an
37+
exception.
38+
39+
[]
40+
41+
For each virtual argument `arg`, the dispatch mechanism calls
42+
`virtual_traits::peek(arg)` and deduces the v-table pointer from the
43+
`result`, using the first of the following methods that applies:
44+
45+
1. If `result` is a `virtual_ptr`, get the pointer to the v-table from it.
46+
2. If `boost_openmethod_vptr` can be called with `result` and a `Registry*`,
47+
and it returns a `vptr_type`, call it.
48+
3. Call `Registry::rtti::dynamic_vptr(result)`.
49+
50+
51+
The macro creates an ordinary inline function in the current scope, with the
52+
`virtual_` decorators removed from the parameter types. `virtual_ptr`{empty}s
53+
are preserved.
54+
55+
NOTE: `ID` must be an *identifier*. Qualified names are not allowed.
56+
57+
NOTE: The default value for `REGISTRY` is the value of
58+
`BOOST_OPENMETHOD_DEFAULT_REGISTRY` at the point `<boost/openmethod/core.hpp>` is
59+
included. Changing the value of this symbol has no effect after that point.
60+
61+
### Implementation Notes
62+
63+
The macro creates several additional constructs:
1764

1865
* A `struct` forward declaration that acts as the method's identifier:
1966

2067
```c++
2168
struct BOOST_OPENMETHOD_ID(ID);
2269
```
2370

24-
* An inline function template, constrained to take the same `PARAMETERS`,
25-
without the `virtual_` decorators, returning a `RETURN_TYPE`. The function
26-
forwards to +
27-
`method<BOOST_OPENMETHOD_ID(ID)(PARAMETERS...), RETURN_TYPE, REGISTRY>::fn`.
71+
* A class template declaration that acts as a container for the method's
72+
overriders in the current scope:
73+
74+
```c++
75+
template<typename...> struct BOOST_OPENMETHOD_OVERRIDERS(NAME);
76+
```
2877

29-
* A guide function used to match overriders with the method:
78+
* A _guide_ function used to match overriders with the method:
3079

3180
```c++
3281
auto BOOST_OPENMETHOD_ID(ID)_guide(...)
@@ -36,9 +85,3 @@ auto BOOST_OPENMETHOD_ID(ID)_guide(...)
3685

3786
* A xref:BOOST_OPENMETHOD_REGISTER.adoc[registrar] that adds the method to the
3887
registry.
39-
40-
NOTE: `ID` must be an *identifier*. Qualified names are not allowed.
41-
42-
NOTE: The default value for `REGISTRY` is the value of
43-
`BOOST_OPENMETHOD_DEFAULT_REGISTRY` at the point `<boost/openmethod/core.hpp>` is
44-
included. Changing the value of this symbol has no effect after that point.

doc/modules/ROOT/pages/BOOST_OPENMETHOD_DECLARE_OVERRIDER.adoc

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,47 @@ Defined in <boost/openmethod/macros.hpp>.
1111

1212
### Description
1313

14-
Declares an overrider for a method.
14+
Declares an overrider for a method, but does not start its definition. This
15+
macro can be used in header files.
1516

16-
The method is deduced from a call to a method guide function with the
17-
overrider's arguments.
17+
`ID` is the identifier of the method to which the overrider is added.
1818

19-
The macro creates several entities in the current scope.
19+
NOTE: `ID` must be an *identifier*. Qualified names are not allowed.
2020

21-
* A class template that acts as a container for the overriders of the methods
22-
called `NAME`:
21+
`PARAMETERS` is a comma-separated list of types, possibly followed by parameter
22+
names, just like in a function declaration.
23+
24+
The macro tries to locate a method that can be called with the same argument
25+
list as the overrider, possibly via argument dependent lookup.
26+
27+
Each `virtual_ptr<T>` in the method's parameter list must have a corresponding
28+
`virtual_ptr<U>` parameter in the same position in the overrider's parameter
29+
list, such that `U` is the same as `T`, or has `T` as an accessible unambiguous
30+
base.
31+
32+
Each `virtual_<T>` in the method's parameter list must have a corresponding `U`
33+
parameter in the same position in the overrider's parameter list, such that `U`
34+
is the same as `T`, or has `T` as an accessible unambiguous base.
35+
36+
### Implementation Notes
37+
38+
The macro creates additional entities in the current scope.
39+
40+
* A class template declaration that acts as a container for the method's
41+
overriders in the current scope:
2342
2443
```c++
25-
template<typename...> BOOST_OPENMETHOD_OVERRIDERS(NAME);
44+
template<typename...> struct BOOST_OPENMETHOD_OVERRIDERS(NAME);
2645
```
2746

28-
* A specialization of the container template for the overrider:
29-
47+
* A specialization of the container for the overrider:
48+
+
49+
--
3050
```c++
31-
struct BOOST_OPENMETHOD_OVERRIDERS(NAME)<RETURN_TYPE(PARAMETERS...)> {
51+
struct BOOST_OPENMETHOD_OVERRIDERS(ID)<RETURN_TYPE(PARAMETERS...)> {
3252
static auto fn(PARAMETERS...) -> RETURN_TYPE;
3353
static auto has_next() -> bool;
3454
template<typename... Args>
3555
static auto next(typename... Args) -> RETURN_TYPE;
3656
};
3757
```
38-
39-
where:
40-
41-
* `fn` is the overrider function.
42-
43-
* `has_next()` returns `true` if a less specialized overrider exists.
44-
45-
* `next(Args... args)` calls the next most specialized overrider via the
46-
pointer stored in the method's `next<fn>` member variable.
47-
48-
`BOOST_OPENMETHOD_DECLARE_OVERRIDER` can be called in a header file, with a
49-
semicolon after the call. It can be called in a header file, but not multiple
50-
times in the same translation unit.
51-
52-
NOTE: `NAME` must be an *identifier*. Qualified names are not allowed.

doc/modules/ROOT/pages/BOOST_OPENMETHOD_INLINE_OVERRIDE.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ BOOST_OPENMETHOD_INLINE_OVERRIDE(ID, (PARAMETERS...), RETURN_TYPE) {
1616
### Description
1717

1818
`BOOST_OPENMETHOD_INLINE_OVERRIDE` performs the same function as
19-
`BOOST_OPENMETHOD_OVERRIDE`, except that the overrider is defined inline.
19+
xref:BOOST_OPENMETHOD_OVERRIDE.adoc[BOOST_OPENMETHOD_OVERRIDE], except that the
20+
overrider is marked `inline`.

doc/modules/ROOT/pages/BOOST_OPENMETHOD_OVERRIDE.adoc

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,49 @@ BOOST_OPENMETHOD_OVERRIDE(ID, (PARAMETERS...), RETURN_TYPE) {
1717

1818
`BOOST_OPENMETHOD_OVERRIDE` adds an overrider to a method.
1919

20-
The method is deduced from a call to a method guide function with the
21-
overrider's arguments.
20+
`ID` is the identifier of the method to which the overrider is added.
2221

23-
The macro creates several entities in the current scope.
22+
NOTE: `ID` must be an *identifier*. Qualified names are not allowed.
23+
24+
`PARAMETERS` is a comma-separated list of types, possibly followed by parameter
25+
names, just like in a function declaration.
26+
27+
The macro tries to locate a method that can be called with the same argument
28+
list as the overrider, possibly via argument dependent lookup.
29+
30+
Each `virtual_ptr<T>` in the method's parameter list must have a corresponding
31+
`virtual_ptr<U>` parameter in the same position in the overrider's parameter
32+
list, such that `U` is the same as `T`, or has `T` as an accessible unambiguous
33+
base.
34+
35+
Each `virtual_<T>` in the method's parameter list must have a corresponding `U`
36+
parameter in the same position in the overrider's parameter list, such that `U`
37+
is the same as `T`, or has `T` as an accessible unambiguous base.
38+
39+
The following names are available inside the overrider's body:
40+
41+
* `fn`: a pointer to a function, the overrider itself. Can be used for recursion.
42+
43+
* `next`: a function with the same signature as the method (minus the
44+
`virtual_<>` decorators). It forwards to the next most specialized overrider, if
45+
it exists and it is unique. If the next overrider does not exist, or is
46+
ambiguous, calling `next` reports a cpp:no_overrider[] or a cpp:ambiguous_call[]
47+
and terminates the program.
48+
49+
* `has_next()`: returns `true` if the next most specialized overrider exists.
2450
25-
* A class template that acts as a container for the overriders of the methods
26-
called `ID`:
51+
### Implementation Notes
52+
53+
The macro creates additional entities in the current scope.
54+
55+
* A class template declaration that acts as a container for the method's
56+
overriders in the current scope:
2757
2858
```c++
29-
template<typename...> BOOST_OPENMETHOD_OVERRIDERS(ID);
59+
template<typename...> struct BOOST_OPENMETHOD_OVERRIDERS(NAME);
3060
```
3161

32-
* A specialization of the container template for the overrider:
62+
* A specialization of the container for the overrider:
3363
+
3464
--
3565
```c++
@@ -40,15 +70,6 @@ struct BOOST_OPENMETHOD_OVERRIDERS(ID)<RETURN_TYPE(PARAMETERS...)> {
4070
static auto next(typename... Args) -> RETURN_TYPE;
4171
};
4272
```
43-
where:
44-
45-
* `fn` is the overrider function.
46-
47-
* `has_next()` returns `true` if a less specialized overrider exists.
48-
49-
* `next(Args... args)` calls the next most specialized overrider via the
50-
pointer stored in the method's `next<fn>` member variable.
51-
--
5273
5374
[]
5475

@@ -66,5 +87,3 @@ auto BOOST_OPENMETHOD_OVERRIDERS(ID)<RETURN_TYPE(PARAMETERS...)>::fn(
6687
{empty}
6788

6889
The `{}` block following the call to the macro is the body of the function.
69-
70-
NOTE: `ID` must be an *identifier*. Qualified names are not allowed.

include/boost/openmethod/core.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,8 @@ using use_classes_tuple_type = boost::mp11::mp_apply<
402402
//! such object per class. The only such case known to the author is when using
403403
//! Windows DLLs.
404404
//!
405-
//! Virtual and multiple inheritance are supported, as long as it is possible to
406-
//! cast the virtual arguments of a method call to the types required by the
407-
//! overriders. The registry's `rtti` policy defines which casts are possible.
408-
//! For the @ref policies::std_rtti (the default), some scenarios involving
409-
//! repeated inheritance may not allow the cast.
405+
//! Virtual and multiple inheritance are supported, with the exclusion of
406+
//! repeated inheritance.
410407
template<class... Classes>
411408
class use_classes {
412409
detail::use_classes_tuple_type<Classes...> tuple;
@@ -2084,7 +2081,7 @@ struct validate_method_parameter<
20842081
//! if it can be called with the arguments passed to the method.
20852082
//!
20862083
//! 2. If the set is empty, call the error handler (if present in the
2087-
//! policy), then terminate the program with `abort`.
2084+
//! registry), then terminate the program with `abort`.
20882085
//!
20892086
//! 3. Remove the overriders that are dominated by other overriders in the
20902087
//! set. Overrider A dominates overrider B if any of its virtual formal
@@ -2235,13 +2232,14 @@ class method<Id, ReturnType(Parameters...), Registry>
22352232
//! @li Have the same number of formal parameters as the method.
22362233
//!
22372234
//! @li Each `virtual_ptr<T>` in the method's parameter list must have a
2238-
//! corresponding `virtual_ptr<U> in the same position in the overrider's
2239-
//! parameter list. The registry's `rtti` policy must have a
2240-
//! `dynamic_cast_ref` that can cast `virtual_ptr<T>` to `virtual_ptr<U>`.
2235+
//! corresponding `virtual_ptr<U>` parameter in the same position in the
2236+
//! overrider's parameter list, such that `U` is the same as `T`, or has
2237+
//! `T` as an accessible unambiguous base.
22412238
//!
22422239
//! @li Each `virtual_<T>` in the method's parameter list must have a
2243-
//! corresponding parameter `U` that the registry's `rtti` policy can cast
2244-
//! from `T` to `U`. Note: `U` must *not* be decorated with `virtual_<>`.
2240+
//! corresponding `U` parameter in the same position in the overrider's
2241+
//! parameter list, such that `U` is the same as `T`, or has `T` as an
2242+
//! accessible unambiguous base.
22452243
//!
22462244
//! @li All other formal parameters must have the same type as the method's
22472245
//! corresponding parameters.

include/boost/openmethod/policies/default_error_handler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace boost::openmethod::policies {
3232
//! enable exception throwing on a registry basis.
3333

3434
struct default_error_handler : error_handler {
35-
//! A model of @ref error_handler::fn.
35+
//! A ErrorHandlerFn metafunction.
3636
//!
3737
//! @tparam Registry The registry containing this policy.
3838
template<class Registry>

include/boost/openmethod/policies/fast_perfect_hash.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::vector<type_id> fast_perfect_hash_control;
3737

3838
namespace policies {
3939

40-
//! Hash a @ref type_id using a fast, perfect hash function
40+
//! Hash type ids using a fast, perfect hash function.
4141
//!
4242
//! `fast_perfect_hash` implements the @ref type_hash policy using a hash
4343
//! function in the form `H(x)=(M*x)>>S`. It attempts to determine values for
@@ -68,7 +68,7 @@ struct fast_perfect_hash : type_hash {
6868

6969
using errors = std::variant<search_error>;
7070

71-
//! A model of @ref type_hash::fn.
71+
//! A TypeHashFn metafunction.
7272
//!
7373
//! @tparam Registry The registry containing this policy
7474
template<class Registry>

include/boost/openmethod/policies/static_rtti.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace boost::openmethod::policies {
2323
//! TODO
2424
//! include::example$static_rtti.cpp[tag=all]
2525
struct static_rtti : rtti {
26-
//! A (partial) model of @ref rtti::fn.
26+
//! A RttiFn metafunction.
2727
//!
2828
//! @tparam Registry The registry containing this policy.
2929
template<class Registry>

0 commit comments

Comments
 (0)