-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/any #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Feature/any #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,7 @@ tmpinst/ | |
|
|
||
| CMakeFiles/ | ||
| build/ | ||
|
|
||
| doc/html/* | ||
| doc/_/* | ||
| cov-int/** | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,196 @@ | ||||||
| // Copyright (c) 2018-2026 Jean-Louis Leroy | ||||||
| // 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) | ||||||
|
|
||||||
| #ifndef BOOST_OPENMETHOD_INTEROP_STD_ANY_HPP | ||||||
| #define BOOST_OPENMETHOD_INTEROP_STD_ANY_HPP | ||||||
|
|
||||||
| #include <any> | ||||||
| #include <boost/openmethod/core.hpp> | ||||||
|
|
||||||
| namespace boost::openmethod { | ||||||
|
|
||||||
| namespace detail { | ||||||
| template<class Registry> | ||||||
| struct validate_method_parameter<virtual_<std::any>, Registry, void> | ||||||
| : std::true_type {}; | ||||||
|
|
||||||
| template<class Registry> | ||||||
| struct validate_method_parameter<virtual_<const std::any&>, Registry, void> | ||||||
| : std::true_type {}; | ||||||
|
|
||||||
| template<class Registry> | ||||||
| struct validate_method_parameter<virtual_<std::any&>, Registry, void> | ||||||
| : std::true_type {}; | ||||||
|
Comment on lines
+19
to
+25
|
||||||
|
|
||||||
| template<class Registry> | ||||||
| struct validate_method_parameter<virtual_<std::any&&>, Registry, void> | ||||||
| : std::true_type {}; | ||||||
|
|
||||||
| } // namespace detail | ||||||
|
|
||||||
| //! Specialize virtual_traits for std::any by value. | ||||||
| //! | ||||||
| //! Dispatch is based on the runtime type of the value stored in the `any`, | ||||||
| //! obtained via `std::any::type()`. Requires the registry to use a @ref | ||||||
| //! rtti policy that provides `dynamic_type` (e.g. @ref std_rtti). | ||||||
| //! | ||||||
| //! @tparam Registry A @ref registry. | ||||||
| template<class Registry> | ||||||
| struct virtual_traits<std::any, Registry> { | ||||||
| //! The type used for dispatch. | ||||||
| using virtual_type = std::any; | ||||||
|
|
||||||
| //! Returns a const reference to the `any` argument. | ||||||
| //! @param arg A reference to a `std::any`. | ||||||
| //! @return A const reference to `arg`. | ||||||
| static auto peek(const std::any& arg) -> const std::any& { | ||||||
| return arg; | ||||||
| } | ||||||
|
|
||||||
| //! Returns a *reference* to a v-table pointer for an object. | ||||||
| //! | ||||||
| //! Acquires the dynamic @ref type_id of `arg`, using the registry's | ||||||
| //! @ref rtti policy. | ||||||
| //! | ||||||
| //! If the registry has a @ref type_hash policy, uses it to convert the | ||||||
| //! type id to an index; otherwise, uses the type_id as the index. | ||||||
| //! | ||||||
| //! If the registry contains the @ref runtime_checks policy, verifies | ||||||
| //! that the index falls within the limits of the vector. If it does | ||||||
| //! not, and if the registry contains a @ref error_handler policy, calls | ||||||
| //! its @ref error function with a @ref missing_class value, then | ||||||
| //! terminates the program with @ref abort. | ||||||
| //! | ||||||
| //! @param arg A reference to a const `any`. | ||||||
| //! @return A reference to a the v-table pointer for `Class`. | ||||||
| static auto dynamic_vptr(const std::any& arg) -> const vptr_type& { | ||||||
| return Registry::rtti::type_vptr(arg.type()); | ||||||
|
||||||
| return Registry::rtti::type_vptr(arg.type()); | |
| return Registry::vptr::type_vptr(&arg.type()); |
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc says this is for std::any& (mutable reference), but the actual specialization is virtual_traits<const std::any&, Registry>. Also, with a const std::any& input, std::any_cast<T&> is not permitted, so the comment about supporting mutable references is misleading. Please update the specialization/signature (if mutability is intended) or adjust the documentation to reflect const-only behavior.
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as the std::any by-value specialization above: Registry::rtti doesn’t provide type_vptr, and arg.type() isn’t a type_id. This should dispatch via the vptr policy (Registry::vptr::type_vptr) using a type_id derived from &arg.type() (for the std_rtti type_id representation).
| return Registry::rtti::type_vptr(arg.type()); | |
| return Registry::vptr::type_vptr(&arg.type()); |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -79,7 +79,21 @@ class vptr_map : public vptr { | |||
| //! @return A reference to a the v-table pointer for `Class`. | ||||
| template<class Class> | ||||
| static auto dynamic_vptr(const Class& arg) -> const vptr_type& { | ||||
| auto type = Registry::rtti::dynamic_type(arg); | ||||
| return type_vptr(Registry::rtti::dynamic_type(arg)); | ||||
| } | ||||
|
|
||||
| //! Returns a *reference* to a v-table pointer for a type. | ||||
| //! | ||||
| //! If the registry contains the @ref runtime_checks policy, checks that | ||||
| //! the map contains the type id. If it does not, and if the registry | ||||
| //! contains a @ref error_handler policy, calls its | ||||
| //! @ref error function with a @ref missing_class value, then | ||||
| //! terminates the program with @ref abort. | ||||
| //! | ||||
| //! @tparam Class A registered class. | ||||
|
||||
| //! @tparam Class A registered class. |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -133,12 +133,29 @@ struct vptr_vector : vptr { | |||
| //! @return A reference to a the v-table pointer for `Class`. | ||||
| template<class Class> | ||||
| static auto dynamic_vptr(const Class& arg) -> const vptr_type& { | ||||
| auto dynamic_type = Registry::rtti::dynamic_type(arg); | ||||
| return type_vptr(Registry::rtti::dynamic_type(arg)); | ||||
| }; | ||||
|
|
||||
| //! Returns a *reference* to a v-table pointer for a type. | ||||
| //! | ||||
| //! If the registry has a @ref type_hash policy, uses it to convert the | ||||
| //! type id to an index; otherwise, uses the type_id as the index. | ||||
| //! | ||||
| //! If the registry contains the @ref runtime_checks policy, verifies | ||||
| //! that the index falls within the limits of the vector. If it does | ||||
| //! not, and if the registry contains a @ref error_handler policy, calls | ||||
| //! its @ref error function with a @ref missing_class value, then | ||||
| //! terminates the program with @ref abort. | ||||
| //! | ||||
| //! @tparam Class A registered class. | ||||
|
||||
| //! @tparam Class A registered class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_dynamic_vptris being instantiated withtype_id, butvirtual_traits<...>::dynamic_vptr(as introduced forstd::any) takes the argument type (e.g.const std::any&). As written, the trait will evaluate to false even whendynamic_vptr(const ArgType&)exists, soacquire_vptrfalls back to the vptr policy path and breaks custom virtual_traits-based dispatch (likely causing compilation failures forstd::any). Update the detection to testdynamic_vptr(std::declval<const ArgType&>())(or equivalent) so thevirtual_traitshook is actually used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback