Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** xref:basics.adoc[Methods and Overriders]
** xref:performance.adoc[Performance]
** xref:smart_pointers.adoc[Smart Pointers]
** xref:headers.adoc[Header and Implementation Files]
** xref:headers.adoc[Headers and Implementation Files]
** xref:namespaces.adoc[Namespaces]
** xref:friends.adoc[Friends]
** xref:multiple_dispatch.adoc[Multiple Dispatch]
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/acknowledgements.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#Acknowledgements]
= Acknowledgements

I would like to thank the C++ Alliance for their support, in particular
Joaquín M. López Muñoz for encouraging me to submit my library and being the
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/basics.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#basics]
= Methods and Overriders

An _open-method_ is a free-standing function that has one or more _virtual_
_parameters_. When it is called, it forwards to an _overrider_ selected from a
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/core_api.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:example: ../examples/core_api/1

[#core_api]
= Core API

OpenMethod provides a macro-free interface: the core API. This is useful in
certain situations, for example when combining open-methods and templates.
Expand Down Expand Up @@ -104,7 +105,7 @@ include::{example}/core_api.cpp[tag=main]

:example: ../examples/core_api/2

### Methods and Templates
## Methods and Templates

The primary purpose of the core API is to make open-methods inter-operate with
templates.
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/custom_rtti.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
:example: ../examples/custom_rtti

[#custom_rtti]
= Custom RTTI

The original motivation for the policy mechanism is to make it possible to
interface OpenMethod with custom RTTI systems.
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/error_handling.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#error_handling]
= Error Handling

Errors can occur during `initialize`, or during method dispatch, if the method's
registry contains the `runtime_checks` policy. If the registry contains an
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/friends.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
:example: ../examples/rolex

[#friendship]
= Friends

Note;; This section uses overrider containers, described in the
xref:headers.adoc[Headers] section.
xref:headers.adoc[Headers and Implementation Files] section.

`friend` is a controversial feature. OpenMethod aims to interact well with all
of C++, as much as feasible for a library, and leaves the choice of using
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/headers.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:example: ../examples/rolex

[#Headers]
= Headers and Implementation Files

Typically, `BOOST_OPENMETHOD` is used in headers, while
`BOOST_OPENMETHOD_CLASSES` and `BOOST_OPENMETHOD_OVERRIDE` are used in
Expand Down
16 changes: 8 additions & 8 deletions doc/modules/ROOT/pages/interop_any.adoc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

[#interop_any]
## Interoperation with `any`
= Interoperation with `any`

OpenMethod can take `any` (both the `std` and `boost` flavors) as virtual
arguments, and dispatch on the type of the contained value. For this purpose, it
regards the types as "deriving" from `any`.

#### Requirements
## Requirements

Dispatch keys on the `std::type_info` returned by `any::type()`, so the
registry's `rtti` policy must be cpp:std_rtti[], or a policy derived from it.
`default_registry` and `indirect_registry` both qualify. A registry with, say,
cpp:static_rtti[] identifies classes by a different kind of `type_id`, and would
look up the wrong v-table; the requirement is enforced with a `static_assert`.

#### `std::any`
## `std::any`

Support is provided by `<boost/openmethod/interop/std_any.hpp>`. It is not
included by `<boost/openmethod.hpp>`, so it must be included explicitly.
Expand All @@ -40,7 +40,7 @@ that has no more specific overrider - in the example below, `float`, which the
include::example$virtual_any.cpp[tag=content]
----

#### Mixing with ordinary virtual parameters
## Mixing with ordinary virtual parameters

A multi-method can take any combination of ordinary virtual parameters and
virtual `any` in the same call:
Expand All @@ -55,7 +55,7 @@ BOOST_OPENMETHOD_OVERRIDE(
}
```

#### Reference categories
## Reference categories

All three reference categories are supported, and they determine what the
overriders may take:
Expand Down Expand Up @@ -95,7 +95,7 @@ auto bump_dog(Dog& dog) -> std::string {
BOOST_OPENMETHOD_REGISTER(bump_method::override<bump_dog>);
```

#### `virtual_std_any`
## `virtual_std_any`

Every call above looks the v-table up in a hash table, keyed on the type the
`any` contains. cpp:virtual_std_any[] - an alias for `virtual_any<std::any>` -
Expand Down Expand Up @@ -131,7 +131,7 @@ contained value's, but whose static type is the `virtual_std_any` - which is
deliberately not a registered class. The combination is rejected at compile
time, cpp:final_virtual_ptr[] included. Pass it by reference instead.

#### `boost::any`
## `boost::any`

`boost::any` is supported as well, by
`<boost/openmethod/interop/boost_any.hpp>`, with cpp:virtual_boost_any[] - the
Expand All @@ -147,6 +147,6 @@ overriders to register the types they name, like the `std::any` and
functions. Boost.TypeErasure's `any` is supported on the same model - see
xref:interop_type_erasure.adoc[Interoperation with Boost.TypeErasure].

### Acknowledgment
## Acknowledgment

This interop is based on a design contributed by Steven Watanabe.
18 changes: 9 additions & 9 deletions doc/modules/ROOT/pages/interop_type_erasure.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[#interop_type_erasure]
## Interoperation with Boost.TypeErasure
= Interoperation with Boost.TypeErasure

Methods can take
link:https://www.boost.org/doc/libs/release/doc/html/boost_typeerasure.html[Boost.TypeErasure]
Expand All @@ -10,7 +10,7 @@ xref:interop_any.adoc[Interoperation with `any`].
Support is provided by `<boost/openmethod/interop/boost_type_erasure.hpp>`. It
is not included by `<boost/openmethod.hpp>`, so it must be included explicitly.

#### Requirements
## Requirements

Dispatch resolves on the type returned by `boost::type_erasure::typeid_of`, so
the ``any``'s concept must include `boost::type_erasure::typeid_<>`.
Expand Down Expand Up @@ -42,7 +42,7 @@ example below, `int` is registered by the `weigh` overrider, and, having no
include::example$type_erasure.cpp[tag=content]
----

#### Reference categories
## Reference categories

The `any` is passed by reference, in any of the three categories -
passing it by value would copy the bound value on every call, and is rejected
Expand Down Expand Up @@ -86,7 +86,7 @@ case, moving the value out of the `any` is performed by the interop code
itself: an overrider taking `Dog&&` receives the bound value ready to be moved
from, and the `any` still owns the moved-from object afterwards.

#### `any` references
## `any` references

Boost.TypeErasure also has non-owning ``any``'s, `any<Concept, _self&>` and
`any<Concept, const _self&>`, which hold a _reference_ to a value stored
Expand All @@ -107,7 +107,7 @@ For the same reason as for `std::any`, cpp:final_virtual_ptr[] is _deleted_
for `type_erasure::any`: it would silently produce the v-table of the root
class rather than the one for the bound value.

#### `virtual_any`
## `virtual_any`

Every call above looks the v-table up in a hash table, keyed on the type the
`any` binds. cpp:virtual_any[] removes that cost: it bundles an `any` with the
Expand All @@ -132,7 +132,7 @@ with `type_erasure::any` for the same reason it works with `std::any` and
types of the `any`. See xref:interop_any.adoc[Interoperation with `any`] for
the details.

#### The `openmethod_vptr` concept
## The `openmethod_vptr` concept

cpp:openmethod_vptr[] is an alternative to `virtual_any`, pursuing the same
goal - constant-time access to the v-table pointer - from the other side.
Expand Down Expand Up @@ -190,7 +190,7 @@ load, and it pays for that in size - the pointer sits next to the `any` - and
in having to acquire it up front.

`openmethod_vptr` is implemented via the cpp:boost_openmethod_vptr[] ADL
customization point.
customization point. See xref:vptr_acquisition.adoc[How the vptr is acquired].

Binding a value to such an `any` also _registers_ its type, as a class derived
from the owning `any` - the registrar is instantiated along with the
Expand Down Expand Up @@ -221,7 +221,7 @@ neither a `vptr` policy nor any policy that one depends on, like `type_hash`.
`registry<policies::static_rtti>` will do. Note that this does not make the
program RTTI-free: Boost.TypeErasure itself uses `typeid`.

#### Empty ``any``s
## Empty ``any``s

An empty relaxed `any` reports `typeid(void)`, which is not a registered
class, so dispatching on it is a cpp:missing_class[] error. A catch-all
Expand All @@ -230,6 +230,6 @@ overrider does not help: dispatch never reaches it. Check with
concept, the failure mode differs: calling a concept operation on an empty
relaxed `any` throws `boost::type_erasure::bad_function_call`.

### Acknowledgment
## Acknowledgment

This interop is based on a design contributed by Steven Watanabe.
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/motivation.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#motivation]
= Motivation

Consider a class hierarchy that represents and evaluates arithmetic
expressions:
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/multiple_dispatch.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:example: ../examples

[#multiple_dispatch]
= Multiple Dispatch

A method can have more than one virtual parameter. This is often called
"multi-method" or "multiple dispatch". All the virtual parameters participate
Expand Down Expand Up @@ -40,7 +41,7 @@ include::{example}/rolex/7/main.cpp[tag=approve]
Because `approve` understands inheritance, we don't have to specify an overrider
for every combination (5 role classes x 6 expense classes = 30 combinations).

### Ambiguities
## Ambiguities

Just like with overload resolution, ambiguities can arise. Let's look at another
example - matrix addition:
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/namespaces.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:example: ../examples/rolex

[#namespaces]
= Namespaces

Note;; This section uses overrider containers, described in the
xref:headers.adoc[Headers and Implementation Files] section.
Expand Down
3 changes: 3 additions & 0 deletions doc/modules/ROOT/pages/performance.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#performance]
= Performance

Open-methods can be as fast as ordinary virtual member functions when
compiled with optimization.
Expand Down Expand Up @@ -110,3 +111,5 @@ thoughout:
----
include::{examplesdir}/ast_virtual_ptr.cpp[tag=content]
----

link:https://godbolt.org/clientstate/eNrNVW2L2kAQ%2FitDCr14xvPUg9JEA21PaKHV45T70hwS454uxN2w2YSjIf3tnd0kvuTUWnqFRtjEmWdn5pndmcmMmMQx5Sw2bPieGXSB744FRuizZeIvCf41gmbTQFHMExFowRvKgjBZEOjPOY9lm0eErYlc8cXVKopcjyUxZUvQStveam07pUImfjiLpHA85rFYiiSQMOJoLPMY4FNC4KcSmg3I8n05ZRJSP0yULsDAJQzgGo3luwYffEH9eUjA3rNdic2NkQYiUrP8rFy9dMFTIgRVhkAQmQgGqQO76HoAd2ES15wrkbmTgH5hWkFcCMmTtOCYVtDlSjYKM%2BqxNd5US8MqtGaB%2BSMOan%2FLrVDNwtBGsCF4Oma9qU5%2FStekzl%2FL%2FucEXL5GAra1QfH2C%2BKvXSU%2BuyI%2BjseT6Wx8Nxx9G04%2Fj2%2FNCLc80WcLjqaO4WpBLNFa6fIt8BjzknK6aBy0Ohs%2FDO%2Fvv9wOzYLhKSdV0biYTnHcT3XMPIZ%2BX0Exjyorf%2BtelY0LEa6%2F913aMRW65RbHgyhnN7ILuHAOofUxvoR7BjQ94zWI6PvvglSv86lo%2BPlcSvhxMpcnyHz6%2BmEyGU7Mkb5Q1blb%2BgisIv5G7ZLXB0CbMiqpH9IfpJwFHlOVuPYpMzfkDtTBdp9Zxbxp4n7WzS2YZz1cg%2Bwmd7YNFRaZj6rcKVsOyRaIyWtZqcoj4ImsrG8EZWIGasFPclX1Ay33kIHhQLsNXehhj7zBNjGA7rXOoRqLAV9HNCRid4IagZqf3V7nWiFCOt9TavZKgf1IzV4l67zvGvkjyngky3FstDDEAQ7fzjtojUs1eSZBInnlrXKO%2F%2F6p6%2FwRf78AaoevWA%3D%3D[Run this example on Compiler Explorer^]
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/registries_and_policies.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#registries_and_policies]
= Registries and Policies

Methods are scoped in a registry. A method can only reference classes in the
same registry. If a class is used as a virtual parameter in methods using
Expand Down Expand Up @@ -52,7 +53,7 @@ it could also be found in namespace `boost::openmethod` - `registry` in
particular.

[#registry_affinity]
### Registry affinity
## Registry affinity

`BOOST_OPENMETHOD_DEFAULT_REGISTRY` is a whole-program answer: one registry, for
every class. A class can instead name its own, by declaring a
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/shared_libraries.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:shared: ../examples/shared_libs

[#shared_libraries]
= Shared Libraries

OpenMethod works with shared libraries on Linux, other POSIX-like platforms,
and Windows. A program and its shared libraries can all contribute classes,
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/smart_pointers.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

[#smart_pointers]
= Smart Pointers

If we want maximum performance, we want to use `virtual_ptr`{empty}s in place of
ordinary pointers or references. However, we may also want to use smart pointers
Expand Down
1 change: 1 addition & 0 deletions doc/modules/ROOT/pages/troubleshooting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:toc-title: Contents

[#troubleshooting]
= Troubleshooting

// The theme draws a rule in a very light grey; on this page, rules separate
// the entries, so they need to stand out.
Expand Down
9 changes: 6 additions & 3 deletions doc/modules/ROOT/pages/virtual_ptr_alt.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:example: ../examples/virtual_ptr_alt

[#virtual_ptr_alt]
## Alternatives to virtual_ptr
= Alternatives to virtual_ptr

Virtual arguments can also be passed as plain references, plain pointers, or
smart pointers, i.e. without using `virtual_ptr`. In a method declaration,
Expand All @@ -27,7 +27,7 @@ inline auto postfix(const Node& node, std::ostream& os) -> void {
}
```

### `boost_openmethod_vptr`
## `boost_openmethod_vptr`

By itself, `virtual_` does not provide any benefits. Passing the virtual
argument by reference almost compiles to the same code as creating a
Expand All @@ -40,6 +40,9 @@ can be called with the virtual argument (passed by const reference) and a
pointer to a registry, and returns a `vptr_type`. If one is found, it is called
to acquire the vptr.

See xref:vptr_acquisition.adoc[How the vptr is acquired] for the other ways a
method can obtain the vptr of a virtual argument.

This is specific to `virtual_` parameters. `virtual_ptr` does not use the
function - it is an alternative to it, not a client of it - and wrapping an
object that provides one is rejected at compile time.
Expand Down Expand Up @@ -72,7 +75,7 @@ mov rcx, qword ptr [rip + value::fn+88]
jmp qword ptr [rax + 8*rcx] # TAILCALL
----

### `inplace_vptr`
## `inplace_vptr`

cpp:inplace_vptr_base[] and cpp:inplace_vptr_derived[] automate the creation and
management of embedded vptrs. They are both
Expand Down
21 changes: 21 additions & 0 deletions doc/modules/ROOT/pages/vptr_acquisition.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[#vptr_acquisition]
= How the vptr is acquired

For each virtual argument, the method calls cpp:virtual_traits[]`::peek` to get
the object to dispatch on, then takes the v-table pointer from the first of the
following that applies:

. If the argument is a `virtual_ptr`, the vptr it carries.
. A cpp:boost_openmethod_vptr[] function found by ADL on the peeked object.
. The `vptr` function of the parameter's `virtual_traits`, if it has one.
. The `dynamic_vptr` function of the registry's cpp:policies::vptr[] policy,
which looks the object's dynamic type up via the cpp:policies::rtti[] policy.

Steps 2 and 3 are for objects that can supply the vptr more directly than step
4 can: an object that embeds it, or one - like a `std::any` - whose dynamic type
is not the type to dispatch on.

NOTE: This is the order dispatch uses. When it reports a cpp:bad_call[], the
library identifies the class of each virtual argument a little differently: an
object that is polymorphic according to the `rtti` policy is identified by its
dynamic type, before the ADL function and `virtual_traits` are consulted.
Loading
Loading