From dfedcc9e131ab1c41e1c481612e6f7f64846605f Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 22 Nov 2026 10:38:35 -0500 Subject: [PATCH 1/6] doc: simplify VirtualTraits::vptr description Replace the long explanation of when to implement vptr with a one-line statement and point to the std::any specialization as the example. Co-Authored-By: Claude Sonnet 5.5 --- include/boost/openmethod/core.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/include/boost/openmethod/core.hpp b/include/boost/openmethod/core.hpp index 9edd2036..42d28594 100644 --- a/include/boost/openmethod/core.hpp +++ b/include/boost/openmethod/core.hpp @@ -4122,15 +4122,8 @@ struct VirtualTraits { //! peeked object; `vptr`; @ref policies::VptrFn::dynamic_vptr of the //! registry's @ref policies::vptr policy. //! - //! Implement `vptr` only if the v-table pointer cannot be obtained from - //! the dynamic type of the peeked object, as reported by the registry's - //! @ref policies::rtti policy, or if it is already at hand. The former is - //! the case for `any`-like types: their dynamic type is the wrapper, not - //! the value they contain. The `std::any` specializations read the - //! @ref type_id of the contained value from `arg.type()`, and pass it to - //! @ref policies::VptrFn::vptr. The latter is the case for a wide type - //! that caches the v-table pointer: @ref virtual_any returns the one it - //! acquired when it was created, without a lookup. + //! Acquire the v-table pointer for `arg`. For an example, see + //! @ref virtual_traits::vptr. //! //! `vptr` must return a *reference*, not a value, so that the caller //! observes the current v-table pointer if the registry contains the From f66d5483845594fda6c600eb163851263c911eda Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 22 Nov 2026 11:00:04 -0500 Subject: [PATCH 2/6] doc: add a page on how the vptr of a virtual argument is acquired State the order once - virtual_ptr, boost_openmethod_vptr, virtual_traits::vptr, the vptr policy's dynamic_vptr - and link to it from boost_openmethod_vptr, VirtualTraits::vptr and the pages that customize the vptr. The page is not in the nav. BOOST_OPENMETHOD drops its own copy of the list, and links to method in See Also. Correct the comment of bad_call_type, which does not follow the same order as dispatch. Co-Authored-By: Claude Sonnet 5.5 --- .../ROOT/pages/interop_type_erasure.adoc | 2 +- doc/modules/ROOT/pages/virtual_ptr_alt.adoc | 3 +++ doc/modules/ROOT/pages/vptr_acquisition.adoc | 21 +++++++++++++++++++ include/boost/openmethod/core.hpp | 9 ++++++-- include/boost/openmethod/macros.hpp | 18 +--------------- 5 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 doc/modules/ROOT/pages/vptr_acquisition.adoc diff --git a/doc/modules/ROOT/pages/interop_type_erasure.adoc b/doc/modules/ROOT/pages/interop_type_erasure.adoc index 0a5e2601..e842033d 100644 --- a/doc/modules/ROOT/pages/interop_type_erasure.adoc +++ b/doc/modules/ROOT/pages/interop_type_erasure.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/virtual_ptr_alt.adoc b/doc/modules/ROOT/pages/virtual_ptr_alt.adoc index 5798b7f3..2e4beef1 100644 --- a/doc/modules/ROOT/pages/virtual_ptr_alt.adoc +++ b/doc/modules/ROOT/pages/virtual_ptr_alt.adoc @@ -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. diff --git a/doc/modules/ROOT/pages/vptr_acquisition.adoc b/doc/modules/ROOT/pages/vptr_acquisition.adoc new file mode 100644 index 00000000..debf0d4c --- /dev/null +++ b/doc/modules/ROOT/pages/vptr_acquisition.adoc @@ -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. diff --git a/include/boost/openmethod/core.hpp b/include/boost/openmethod/core.hpp index 42d28594..ef97a69d 100644 --- a/include/boost/openmethod/core.hpp +++ b/include/boost/openmethod/core.hpp @@ -905,6 +905,7 @@ BOOST_FORCEINLINE auto use_reflected_classes( //! //! @see @ref inplace_vptr_base //! @see [Virtual Pointer Alternatives](xref:ROOT:virtual_ptr_alt.adoc) +//! @see [How the vptr is acquired](xref:ROOT:vptr_acquisition.adoc) //! @see [Custom RTTI](xref:ROOT:custom_rtti.adoc) void boost_openmethod_vptr(...); @@ -2322,8 +2323,10 @@ auto class_of_vptr(vptr_type vptr, type_id declared) -> type_id { return found; } -// The class of a virtual argument, for a `bad_call`, read through the routes -// `method::vptr` takes to dispatch it. `Parameter` is the parameter's type, +// The class of a virtual argument, for a `bad_call`. The routes are those of +// `method::vptr`, with one difference: an object that is polymorphic according +// to the rtti policy is identified by its dynamic type, before the ADL function +// and the `virtual_traits` are tried. `Parameter` is the parameter's type, // stripped of `virtual_`: its `virtual_traits` may read the class of a value a // type-erased argument (an `any`) holds. template @@ -4129,6 +4132,8 @@ struct VirtualTraits { //! observes the current v-table pointer if the registry contains the //! @ref policies::indirect_vptr policy and `initialize` is called again. //! + //! @see [How the vptr is acquired](xref:ROOT:vptr_acquisition.adoc) + //! //! @param arg The object returned by @ref peek. //! @return A reference to the v-table pointer for `arg`. static auto vptr(const virtual_type& arg) -> const vptr_type&; diff --git a/include/boost/openmethod/macros.hpp b/include/boost/openmethod/macros.hpp index 998fbd92..6c9e5abe 100644 --- a/include/boost/openmethod/macros.hpp +++ b/include/boost/openmethod/macros.hpp @@ -189,23 +189,6 @@ inline constexpr bool method_not_found = false; //! prior to calling `abort`. `error` may prevent termination by throwing an //! exception. //! -//! For each virtual argument `arg`, the dispatch mechanism calls -//! `virtual_traits::peek(arg)` and deduces the v-table pointer from the -//! `result`, using the first of the following methods that applies: -//! -//! @li If `result` is a `virtual_ptr`, get the pointer to the v-table from it. -//! -//! @li If -//! [boost_openmethod_vptr](xref:reference:boost/openmethod/boost_openmethod_vptr.adoc) -//! can be called with `result` and a `Registry*`, and it returns a -//! `vptr_type`, call it. -//! -//! @li If `virtual_traits` provides a `vptr` function, call it. -//! -//! @li Call the -//! [dynamic_vptr](xref:reference:boost/openmethod/policies/VptrFn/dynamic_vptr.adoc) -//! of the registry's `vptr` policy. -//! //! The macro creates an ordinary inline function in the current scope, with the //! `virtual_` decorators removed from the parameter types. `virtual_ptr` //! parameters are preserved. @@ -254,6 +237,7 @@ inline constexpr bool method_not_found = false; //! @param PARAMETERS The method's parameter list, in parentheses. //! @param ... The method's return type, optionally followed by the registry. //! +//! @see @ref boost::openmethod::method //! @see [Methods and Overriders](xref:ROOT:basics.adoc) //! @see [Header and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD(ID, PARAMETERS, ...) \ From 3a8d5f83b9ecf1a16b3183917ddac0acf7e1b9fb Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 22 Nov 2026 11:08:04 -0500 Subject: [PATCH 3/6] doc: give every page a title Antora takes the browser title from a level-0 heading, which the pages lacked: all of them read "Untitled :: Boost.OpenMethod". Add one to each, named as in the nav. Where the page opened with a section of the same name, that section becomes the title. Shift the section headings up to follow, so Asciidoctor no longer reports them out of sequence. Co-Authored-By: Claude Sonnet 5.5 --- doc/modules/ROOT/nav.adoc | 2 +- doc/modules/ROOT/pages/acknowledgements.adoc | 1 + doc/modules/ROOT/pages/basics.adoc | 1 + doc/modules/ROOT/pages/core_api.adoc | 3 ++- doc/modules/ROOT/pages/custom_rtti.adoc | 1 + doc/modules/ROOT/pages/error_handling.adoc | 1 + doc/modules/ROOT/pages/friends.adoc | 3 ++- doc/modules/ROOT/pages/headers.adoc | 1 + doc/modules/ROOT/pages/interop_any.adoc | 16 ++++++++-------- doc/modules/ROOT/pages/interop_type_erasure.adoc | 16 ++++++++-------- doc/modules/ROOT/pages/motivation.adoc | 1 + doc/modules/ROOT/pages/multiple_dispatch.adoc | 3 ++- doc/modules/ROOT/pages/namespaces.adoc | 1 + doc/modules/ROOT/pages/performance.adoc | 1 + .../ROOT/pages/registries_and_policies.adoc | 3 ++- doc/modules/ROOT/pages/shared_libraries.adoc | 1 + doc/modules/ROOT/pages/smart_pointers.adoc | 1 + doc/modules/ROOT/pages/troubleshooting.adoc | 1 + doc/modules/ROOT/pages/virtual_ptr_alt.adoc | 6 +++--- doc/modules/ROOT/pages/vptr_acquisition.adoc | 2 +- include/boost/openmethod/macros.hpp | 12 ++++++------ 21 files changed, 46 insertions(+), 31 deletions(-) diff --git a/doc/modules/ROOT/nav.adoc b/doc/modules/ROOT/nav.adoc index 2b470949..6f86a2a6 100644 --- a/doc/modules/ROOT/nav.adoc +++ b/doc/modules/ROOT/nav.adoc @@ -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] diff --git a/doc/modules/ROOT/pages/acknowledgements.adoc b/doc/modules/ROOT/pages/acknowledgements.adoc index 266072b8..d9603980 100644 --- a/doc/modules/ROOT/pages/acknowledgements.adoc +++ b/doc/modules/ROOT/pages/acknowledgements.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/basics.adoc b/doc/modules/ROOT/pages/basics.adoc index 8b760187..723c48fe 100644 --- a/doc/modules/ROOT/pages/basics.adoc +++ b/doc/modules/ROOT/pages/basics.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/core_api.adoc b/doc/modules/ROOT/pages/core_api.adoc index a79afc25..0682cd2e 100644 --- a/doc/modules/ROOT/pages/core_api.adoc +++ b/doc/modules/ROOT/pages/core_api.adoc @@ -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. @@ -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. diff --git a/doc/modules/ROOT/pages/custom_rtti.adoc b/doc/modules/ROOT/pages/custom_rtti.adoc index 30e5bdb0..63ac555d 100644 --- a/doc/modules/ROOT/pages/custom_rtti.adoc +++ b/doc/modules/ROOT/pages/custom_rtti.adoc @@ -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. diff --git a/doc/modules/ROOT/pages/error_handling.adoc b/doc/modules/ROOT/pages/error_handling.adoc index bc9b616f..5c7f69c8 100644 --- a/doc/modules/ROOT/pages/error_handling.adoc +++ b/doc/modules/ROOT/pages/error_handling.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/friends.adoc b/doc/modules/ROOT/pages/friends.adoc index dbe82d44..81b02f3e 100644 --- a/doc/modules/ROOT/pages/friends.adoc +++ b/doc/modules/ROOT/pages/friends.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/headers.adoc b/doc/modules/ROOT/pages/headers.adoc index 92802fff..8f2f420f 100644 --- a/doc/modules/ROOT/pages/headers.adoc +++ b/doc/modules/ROOT/pages/headers.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/interop_any.adoc b/doc/modules/ROOT/pages/interop_any.adoc index 194b338c..dd80f2aa 100644 --- a/doc/modules/ROOT/pages/interop_any.adoc +++ b/doc/modules/ROOT/pages/interop_any.adoc @@ -1,12 +1,12 @@ [#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. @@ -14,7 +14,7 @@ registry's `rtti` policy must be cpp:std_rtti[], or a policy derived from it. 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 ``. It is not included by ``, so it must be included explicitly. @@ -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: @@ -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: @@ -95,7 +95,7 @@ auto bump_dog(Dog& dog) -> std::string { BOOST_OPENMETHOD_REGISTER(bump_method::override); ``` -#### `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` - @@ -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 ``, with cpp:virtual_boost_any[] - the @@ -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. diff --git a/doc/modules/ROOT/pages/interop_type_erasure.adoc b/doc/modules/ROOT/pages/interop_type_erasure.adoc index e842033d..38675509 100644 --- a/doc/modules/ROOT/pages/interop_type_erasure.adoc +++ b/doc/modules/ROOT/pages/interop_type_erasure.adoc @@ -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] @@ -10,7 +10,7 @@ xref:interop_any.adoc[Interoperation with `any`]. Support is provided by ``. It is not included by ``, 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_<>`. @@ -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 @@ -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` and `any`, which hold a _reference_ to a value stored @@ -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 @@ -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. @@ -221,7 +221,7 @@ neither a `vptr` policy nor any policy that one depends on, like `type_hash`. `registry` 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 @@ -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. diff --git a/doc/modules/ROOT/pages/motivation.adoc b/doc/modules/ROOT/pages/motivation.adoc index df6a7b0e..c3940672 100644 --- a/doc/modules/ROOT/pages/motivation.adoc +++ b/doc/modules/ROOT/pages/motivation.adoc @@ -1,5 +1,6 @@ [#motivation] += Motivation Consider a class hierarchy that represents and evaluates arithmetic expressions: diff --git a/doc/modules/ROOT/pages/multiple_dispatch.adoc b/doc/modules/ROOT/pages/multiple_dispatch.adoc index db8bee23..06963d53 100644 --- a/doc/modules/ROOT/pages/multiple_dispatch.adoc +++ b/doc/modules/ROOT/pages/multiple_dispatch.adoc @@ -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 @@ -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: diff --git a/doc/modules/ROOT/pages/namespaces.adoc b/doc/modules/ROOT/pages/namespaces.adoc index dbc05e23..199cb19c 100644 --- a/doc/modules/ROOT/pages/namespaces.adoc +++ b/doc/modules/ROOT/pages/namespaces.adoc @@ -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. diff --git a/doc/modules/ROOT/pages/performance.adoc b/doc/modules/ROOT/pages/performance.adoc index e8e73f78..b0afa2c4 100644 --- a/doc/modules/ROOT/pages/performance.adoc +++ b/doc/modules/ROOT/pages/performance.adoc @@ -1,5 +1,6 @@ [#performance] += Performance Open-methods can be as fast as ordinary virtual member functions when compiled with optimization. diff --git a/doc/modules/ROOT/pages/registries_and_policies.adoc b/doc/modules/ROOT/pages/registries_and_policies.adoc index 635e5bd2..7d9b9851 100644 --- a/doc/modules/ROOT/pages/registries_and_policies.adoc +++ b/doc/modules/ROOT/pages/registries_and_policies.adoc @@ -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 @@ -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 diff --git a/doc/modules/ROOT/pages/shared_libraries.adoc b/doc/modules/ROOT/pages/shared_libraries.adoc index cdbc77cb..fdcb054c 100644 --- a/doc/modules/ROOT/pages/shared_libraries.adoc +++ b/doc/modules/ROOT/pages/shared_libraries.adoc @@ -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, diff --git a/doc/modules/ROOT/pages/smart_pointers.adoc b/doc/modules/ROOT/pages/smart_pointers.adoc index cfd17665..3d879941 100644 --- a/doc/modules/ROOT/pages/smart_pointers.adoc +++ b/doc/modules/ROOT/pages/smart_pointers.adoc @@ -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 diff --git a/doc/modules/ROOT/pages/troubleshooting.adoc b/doc/modules/ROOT/pages/troubleshooting.adoc index a25f70ce..f68afa5e 100644 --- a/doc/modules/ROOT/pages/troubleshooting.adoc +++ b/doc/modules/ROOT/pages/troubleshooting.adoc @@ -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. diff --git a/doc/modules/ROOT/pages/virtual_ptr_alt.adoc b/doc/modules/ROOT/pages/virtual_ptr_alt.adoc index 2e4beef1..32a868b9 100644 --- a/doc/modules/ROOT/pages/virtual_ptr_alt.adoc +++ b/doc/modules/ROOT/pages/virtual_ptr_alt.adoc @@ -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, @@ -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 @@ -75,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 diff --git a/doc/modules/ROOT/pages/vptr_acquisition.adoc b/doc/modules/ROOT/pages/vptr_acquisition.adoc index debf0d4c..1366db24 100644 --- a/doc/modules/ROOT/pages/vptr_acquisition.adoc +++ b/doc/modules/ROOT/pages/vptr_acquisition.adoc @@ -1,5 +1,5 @@ [#vptr_acquisition] -## How the vptr is acquired += 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 diff --git a/include/boost/openmethod/macros.hpp b/include/boost/openmethod/macros.hpp index 6c9e5abe..705cb7d3 100644 --- a/include/boost/openmethod/macros.hpp +++ b/include/boost/openmethod/macros.hpp @@ -114,7 +114,7 @@ inline constexpr bool method_not_found = false; //! //! @param ID The method's name. //! -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD_OVERRIDERS(ID) \ BOOST_PP_CAT(BOOST_OPENMETHOD_ID(ID), _overriders) @@ -239,7 +239,7 @@ inline constexpr bool method_not_found = false; //! //! @see @ref boost::openmethod::method //! @see [Methods and Overriders](xref:ROOT:basics.adoc) -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD(ID, PARAMETERS, ...) \ struct BOOST_OPENMETHOD_ID(ID); \ using BOOST_OPENMETHOD_GENSYM = \ @@ -364,7 +364,7 @@ inline constexpr bool method_not_found = false; //! @param PARAMETERS The overrider's parameter list, in parentheses. //! @param ... The overrider's return type. //! -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD_DECLARE_OVERRIDER(ID, PARAMETERS, ...) \ template \ struct BOOST_OPENMETHOD_OVERRIDERS(ID); \ @@ -430,7 +430,7 @@ inline constexpr bool method_not_found = false; //! @param PARAMETERS The overrider's parameter list, in parentheses. //! @param ... The overrider's return type. //! -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD_DEFINE_OVERRIDER(ID, PARAMETERS, ...) \ BOOST_OPENMETHOD_DETAIL_REGISTER_OVERRIDER(ID, PARAMETERS, __VA_ARGS__) \ auto BOOST_OPENMETHOD_OVERRIDER( \ @@ -516,7 +516,7 @@ inline constexpr bool method_not_found = false; //! @param ... The overrider's return type. //! //! @see [Methods and Overriders](xref:ROOT:basics.adoc) -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) //! @see [Namespaces](xref:ROOT:namespaces.adoc) //! @see [Friends](xref:ROOT:friends.adoc) #define BOOST_OPENMETHOD_OVERRIDE(ID, PARAMETERS, ...) \ @@ -564,7 +564,7 @@ inline constexpr bool method_not_found = false; //! @param PARAMETERS The overrider's parameter list, in parentheses. //! @param ... The overrider's return type. //! -//! @see [Header and Implementation Files](xref:ROOT:headers.adoc) +//! @see [Headers and Implementation Files](xref:ROOT:headers.adoc) #define BOOST_OPENMETHOD_INLINE_OVERRIDE(ID, PARAMETERS, ...) \ BOOST_OPENMETHOD_DECLARE_OVERRIDER(ID, PARAMETERS, __VA_ARGS__) \ BOOST_OPENMETHOD_DETAIL_REGISTER_OVERRIDER_AUX( \ From 3720bfadb0094352f1d0650848fb80b863c42fbc Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 22 Nov 2026 11:43:51 -0500 Subject: [PATCH 4/6] doc: performance: link the virtual_ptr Node example to Compiler Explorer The link runs the example against the Boost release CE offers, as the others do. Co-Authored-By: Claude Sonnet 5.5 --- doc/modules/ROOT/pages/performance.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/modules/ROOT/pages/performance.adoc b/doc/modules/ROOT/pages/performance.adoc index b0afa2c4..8ee944fb 100644 --- a/doc/modules/ROOT/pages/performance.adoc +++ b/doc/modules/ROOT/pages/performance.adoc @@ -111,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^] From 13053039e8a7cf80a92ce0ff598c8fd0eb317c40 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Thu, 26 Nov 2026 10:52:26 -0500 Subject: [PATCH 5/6] doc: hide no_checks and with_checks from the reference Exclude the policies' no_checks/with_checks state types from the reference and drop the @ref links to them in fast_perfect_hash::fn. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_016fFU6iQPU1xuk7zqr2XGQx --- doc/mrdocs.yml | 2 ++ include/boost/openmethod/policies/fast_perfect_hash.hpp | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/mrdocs.yml b/doc/mrdocs.yml index a2eeb20d..e5cad4b5 100644 --- a/doc/mrdocs.yml +++ b/doc/mrdocs.yml @@ -23,6 +23,8 @@ exclude-symbols: - 'boost::openmethod::registry::finalize' - 'boost::openmethod::boost_openmethod_bases' - 'boost::openmethod::registry_state::st' + - 'boost::openmethod::policies::*::no_checks' + - 'boost::openmethod::policies::*::with_checks' # Macros. Only the public macros carry a doc comment, and with # `extract-all-macros` off (the default) MrDocs extracts only documented ones. diff --git a/include/boost/openmethod/policies/fast_perfect_hash.hpp b/include/boost/openmethod/policies/fast_perfect_hash.hpp index d216d897..7653263d 100644 --- a/include/boost/openmethod/policies/fast_perfect_hash.hpp +++ b/include/boost/openmethod/policies/fast_perfect_hash.hpp @@ -122,10 +122,9 @@ struct fast_perfect_hash : type_hash { template class fn { public: - //! The policy's state: the hash factors (@ref no_checks), plus the - //! control table if the registry has runtime checks enabled (@ref - //! with_checks). Held in the registry's shared state (see @ref - //! registry_state). + //! The policy's state: the hash factors, plus the control table if + //! the registry has runtime checks enabled. Held in the registry's + //! shared state (see @ref registry_state). using state = std::conditional_t< Registry::has_runtime_checks, with_checks, no_checks>; From 0344b7c8f0305fda84c904226ec22b76caf0b6e3 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sat, 28 Nov 2026 19:39:05 -0500 Subject: [PATCH 6/6] doc: show each hash policy's hash inside a virtual_ptr construction The assembly in the doc comment of each hash policy showed a bare call to `hash`, which hides the cost that matters: what constructing a `virtual_ptr` from a reference costs. Show that instead, from loading the v-table to fetching the object's vptr, with the instructions that compute the hash highlighted. Each policy also links to the other three. Regenerated with x86-64 clang 22, -std=c++17 -O2 (-mbmi2 for minimal_cover_hash), from the updated hash_call_.cpp examples. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016fFU6iQPU1xuk7zqr2XGQx --- .../examples/hash_call_fast_perfect_hash.cpp | 17 ++++++-- .../examples/hash_call_minimal_cover_hash.cpp | 19 +++++++-- .../hash_call_minimal_perfect_hash.cpp | 21 +++++++--- .../examples/hash_call_two_level_hash.cpp | 21 +++++++--- .../openmethod/policies/fast_perfect_hash.hpp | 28 ++++++++----- .../policies/minimal_cover_hash.hpp | 26 ++++++++---- .../policies/minimal_perfect_hash.hpp | 39 +++++++++++------- .../openmethod/policies/two_level_hash.hpp | 41 ++++++++++++------- 8 files changed, 147 insertions(+), 65 deletions(-) diff --git a/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp b/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp index 47eefebf..f45a4e9f 100644 --- a/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp +++ b/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp @@ -5,15 +5,24 @@ // clang-format off -// tag::content[] #include using namespace boost::openmethod; -auto hash_of(type_id type) -> std::size_t { - return policies::fast_perfect_hash::fn::hash(type); +struct Animal { + virtual ~Animal() = default; +}; + +struct Dog : Animal {}; + +virtual_ptr sink; + +void construct(Animal& snoopy) { + // tag::content[] + virtual_ptr animal = snoopy; + // end::content[] + sink = animal; } -// end::content[] int main() { } diff --git a/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp b/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp index bf2bcf5b..3a5f27f0 100644 --- a/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp +++ b/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp @@ -13,13 +13,24 @@ using namespace boost::openmethod; #if BOOST_OPENMETHOD_HAS_PEXT // tag::content[] -struct hashed_registry +struct custom_registry : default_registry::with> {}; +// end::content[] + +struct Animal { + virtual ~Animal() = default; +}; + +struct Dog : Animal {}; -auto hash_of(type_id type) -> std::size_t { - return policies::minimal_cover_hash<>::fn::hash(type); +virtual_ptr sink; + +void construct(Animal& snoopy) { + // tag::content[] + virtual_ptr animal = snoopy; + // end::content[] + sink = animal; } -// end::content[] #endif diff --git a/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp b/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp index f92ff000..b87232ac 100644 --- a/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp +++ b/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp @@ -5,19 +5,30 @@ // clang-format off -// tag::content[] #include #include using namespace boost::openmethod; -struct hashed_registry +// tag::content[] +struct custom_registry : default_registry::with> {}; +// end::content[] + +struct Animal { + virtual ~Animal() = default; +}; -auto hash_of(type_id type) -> std::size_t { - return policies::minimal_perfect_hash<>::fn::hash(type); +struct Dog : Animal {}; + +virtual_ptr sink; + +void construct(Animal& snoopy) { + // tag::content[] + virtual_ptr animal = snoopy; + // end::content[] + sink = animal; } -// end::content[] int main() { } diff --git a/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp b/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp index 9ee5b64b..cfa9a2d0 100644 --- a/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp +++ b/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp @@ -5,19 +5,30 @@ // clang-format off -// tag::content[] #include #include using namespace boost::openmethod; -struct hashed_registry +// tag::content[] +struct custom_registry : default_registry::with> {}; +// end::content[] + +struct Animal { + virtual ~Animal() = default; +}; -auto hash_of(type_id type) -> std::size_t { - return policies::two_level_hash<>::fn::hash(type); +struct Dog : Animal {}; + +virtual_ptr sink; + +void construct(Animal& snoopy) { + // tag::content[] + virtual_ptr animal = snoopy; + // end::content[] + sink = animal; } -// end::content[] int main() { } diff --git a/include/boost/openmethod/policies/fast_perfect_hash.hpp b/include/boost/openmethod/policies/fast_perfect_hash.hpp index 7653263d..4f94bbcb 100644 --- a/include/boost/openmethod/policies/fast_perfect_hash.hpp +++ b/include/boost/openmethod/policies/fast_perfect_hash.hpp @@ -66,25 +66,33 @@ namespace policies { //! range of integers. In other words, a lot of space may be wasted in presence //! of large sets of type_ids. //! -//! The code generated for a call to `hash`, by x86-64 clang 22 with -//! `-O2`, where `st` stands for the registry's state: +//! The code generated by x86-64 clang 22 with `-O2` for constructing a +//! `virtual_ptr` from `snoopy`, an `Animal&` whose dynamic type is not known at +//! compile time; `st` stands for the registry's state. No custom registry is +//! needed: @ref default_registry uses `fast_perfect_hash`. //! //! @code -//! auto hash_of(type_id type) -> std::size_t { -//! return policies::fast_perfect_hash::fn::hash(type); -//! } +//! virtual_ptr animal = snoopy; //! @endcode //! -//! @code -//! imul rdi, qword ptr [rip + st+48] -//! movzx eax, byte ptr [rip + st+56] -//! shrx rax, rdi, rax -//! ret +//! The highlighted instructions compute the hash: +//! +//! @code{.asm} +//! mov rax, qword ptr [rdi] ; snoopy's v-table +//! #mov rdx, qword ptr [rip + st+48]# +//! #imul rdx, qword ptr [rax - 8]# ; [rax - 8] is &typeid(snoopy) +//! #movzx ecx, byte ptr [rip + st+56]# +//! #shr rdx, cl# +//! mov rax, qword ptr [rip + st+80] +//! mov rax, qword ptr [rax + 8*rdx] //! @endcode //! //! @par Example //! include:policies.cpp#fast_perfect_hash //! +//! @see @ref minimal_perfect_hash +//! @see @ref two_level_hash +//! @see @ref minimal_cover_hash //! @see [Registries and Policies](xref:ROOT:registries_and_policies.adoc) struct fast_perfect_hash : type_hash { diff --git a/include/boost/openmethod/policies/minimal_cover_hash.hpp b/include/boost/openmethod/policies/minimal_cover_hash.hpp index 44cf1f69..536f80fe 100644 --- a/include/boost/openmethod/policies/minimal_cover_hash.hpp +++ b/include/boost/openmethod/policies/minimal_cover_hash.hpp @@ -192,23 +192,33 @@ namespace policies { //! @tparam MaxBits Refuse a cover wider than this; the table is `8 << bits` //! bytes. //! -//! The code generated for a call to `hash`, by x86-64 clang 22 with -//! `-O2` and `-mbmi2`, where `st` stands for the registry's state: +//! The code generated by x86-64 clang 22 with `-O2` and `-mbmi2` for +//! constructing a `virtual_ptr` from `snoopy`, an `Animal&` whose dynamic type +//! is not known at compile time; `st` stands for the registry's state: //! //! @code -//! auto hash_of(type_id type) -> std::size_t { -//! return policies::minimal_cover_hash<>::fn::hash(type); -//! } +//! struct custom_registry +//! : default_registry::with> {}; +//! +//! virtual_ptr animal = snoopy; //! @endcode //! -//! @code -//! pext rax, rdi, qword ptr [rip + st+48] -//! ret +//! The highlighted instructions compute the hash: +//! +//! @code{.asm} +//! mov rax, qword ptr [rdi] ; snoopy's v-table +//! mov rax, qword ptr [rax - 8] ; &typeid(snoopy) +//! #pext rax, rax, qword ptr [rip + st+48]# +//! mov rcx, qword ptr [rip + st+64] +//! mov rax, qword ptr [rcx + 8*rax] //! @endcode //! //! @par Example //! include:policies.cpp#minimal_cover_hash //! +//! @see @ref fast_perfect_hash +//! @see @ref minimal_perfect_hash +//! @see @ref two_level_hash //! @see [Registries and Policies](xref:ROOT:registries_and_policies.adoc) template struct minimal_cover_hash : type_hash { diff --git a/include/boost/openmethod/policies/minimal_perfect_hash.hpp b/include/boost/openmethod/policies/minimal_perfect_hash.hpp index f699146b..ece7d971 100644 --- a/include/boost/openmethod/policies/minimal_perfect_hash.hpp +++ b/include/boost/openmethod/policies/minimal_perfect_hash.hpp @@ -102,29 +102,40 @@ namespace boost::openmethod::policies { //! defeats one multiplier usually defeats them all at that `Lambda` and //! `LoadPercent`; lower `Lambda` or `LoadPercent` instead. //! -//! The code generated for a call to `hash`, by x86-64 clang 22 with -//! `-O2`, where `st` stands for the registry's state: +//! The code generated by x86-64 clang 22 with `-O2` for constructing a +//! `virtual_ptr` from `snoopy`, an `Animal&` whose dynamic type is not known at +//! compile time; `st` stands for the registry's state: //! //! @code -//! auto hash_of(type_id type) -> std::size_t { -//! return policies::minimal_perfect_hash<>::fn::hash(type); -//! } +//! struct custom_registry +//! : default_registry::with> {}; +//! +//! virtual_ptr animal = snoopy; //! @endcode //! -//! @code -//! imul rdi, qword ptr [rip + st+48] -//! movzx eax, byte ptr [rip + st+56] -//! shrx rax, rdi, rax -//! mov rcx, qword ptr [rip + st+72] -//! mov edx, dword ptr [rcx + 4*rax] -//! imul rdx, rdi -//! mulx rax, rax, qword ptr [rip + st+64] -//! ret +//! The highlighted instructions compute the hash: +//! +//! @code{.asm} +//! mov rax, qword ptr [rdi] ; snoopy's v-table +//! #mov rdx, qword ptr [rip + st+48]# +//! #imul rdx, qword ptr [rax - 8]# ; [rax - 8] is &typeid(snoopy) +//! #movzx ecx, byte ptr [rip + st+56]# +//! #mov rax, rdx# +//! #shr rax, cl# +//! #mov rcx, qword ptr [rip + st+72]# +//! #mov eax, dword ptr [rcx + 4*rax]# +//! #imul rax, rdx# +//! #mul qword ptr [rip + st+64]# +//! mov rax, qword ptr [rip + st+96] +//! mov rax, qword ptr [rax + 8*rdx] //! @endcode //! //! @par Example //! include:policies.cpp#minimal_perfect_hash //! +//! @see @ref fast_perfect_hash +//! @see @ref two_level_hash +//! @see @ref minimal_cover_hash //! @see [Registries and Policies](xref:ROOT:registries_and_policies.adoc) template< std::size_t Lambda = 4, std::size_t LoadPercent = 95, diff --git a/include/boost/openmethod/policies/two_level_hash.hpp b/include/boost/openmethod/policies/two_level_hash.hpp index 6a5818ac..ce2f45fd 100644 --- a/include/boost/openmethod/policies/two_level_hash.hpp +++ b/include/boost/openmethod/policies/two_level_hash.hpp @@ -86,30 +86,41 @@ namespace boost::openmethod::policies { //! a pathological input ask for a table orders of magnitude larger than the //! program needs. //! -//! The code generated for a call to `hash`, by x86-64 clang 22 with -//! `-O2`, where `st` stands for the registry's state: +//! The code generated by x86-64 clang 22 with `-O2` for constructing a +//! `virtual_ptr` from `snoopy`, an `Animal&` whose dynamic type is not known at +//! compile time; `st` stands for the registry's state: //! //! @code -//! auto hash_of(type_id type) -> std::size_t { -//! return policies::two_level_hash<>::fn::hash(type); -//! } +//! struct custom_registry +//! : default_registry::with> {}; +//! +//! virtual_ptr animal = snoopy; //! @endcode //! -//! @code -//! imul rdi, qword ptr [rip + st+48] -//! movzx eax, byte ptr [rip + st+56] -//! shrx rax, rdi, rax -//! mov rcx, qword ptr [rip + st+72] -//! mov eax, dword ptr [rcx + 4*rax] -//! imul rax, rdi -//! movzx ecx, byte ptr [rip + st+64] -//! shrx rax, rax, rcx -//! ret +//! The highlighted instructions compute the hash: +//! +//! @code{.asm} +//! mov rax, qword ptr [rdi] ; snoopy's v-table +//! #mov rdx, qword ptr [rip + st+48]# +//! #imul rdx, qword ptr [rax - 8]# ; [rax - 8] is &typeid(snoopy) +//! #movzx ecx, byte ptr [rip + st+56]# +//! #mov rax, rdx# +//! #shr rax, cl# +//! #mov rcx, qword ptr [rip + st+72]# +//! #mov eax, dword ptr [rcx + 4*rax]# +//! #imul rax, rdx# +//! #movzx ecx, byte ptr [rip + st+64]# +//! #shr rax, cl# +//! mov rcx, qword ptr [rip + st+104] +//! mov rax, qword ptr [rcx + 8*rax] //! @endcode //! //! @par Example //! include:policies.cpp#two_level_hash //! +//! @see @ref fast_perfect_hash +//! @see @ref minimal_perfect_hash +//! @see @ref minimal_cover_hash //! @see [Registries and Policies](xref:ROOT:registries_and_policies.adoc) template struct two_level_hash : type_hash {