register classes by reflection in C++26 - #94
Open
jll63 wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
An automated preview of the documentation is available at https://94.openmethod.prtest3.cppalliance.org/libs/openmethod/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-08-25 15:16:19 UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #89.
When the compiler supports C++26 reflection (P2996), the library can find the
classes taking part in dispatch on its own, and
BOOST_OPENMETHOD_CLASSESbecomes unnecessary in most cases.
What's new
use_classes_in<^^Namespace, Registry>(core.hpp) — a registrar thatscans a namespace by reflection for the classes involved in dispatch, plus
their bases, and registers them. Virtual and multiple inheritance are
supported; unlike
use_classes, repeated inheritance is not an error here —an ambiguous base cannot take part in dispatch, so it is left out.
BOOST_OPENMETHOD_CLASSES_IN(NAMESPACE, ...)(macros.hpp) — the macrowrapper. Reflection sees only what precedes it, so it goes at the bottom of
the file. Without reflection it expands to nothing, so a file that also calls
BOOST_OPENMETHOD_CLASSESbuilds under either standard.policies::explicit_class_registration(preamble.hpp) — opts a registryout, restoring the C++17 behaviour where every class must be registered by
hand. The registry exposes
has_reflected_class_registration. The policy hasno effect if the compiler does not support reflection.
Methods are found through the names that denote them — the
usingdeclarationBOOST_OPENMETHODnow emits, a hand-written one, or any registrar object. Acore-interface method whose
method<...>type is spelled out in full at everyuse, with neither a
usingdeclaration nor an overrider, is named by nothingand is not found; its classes still need
use_classes.Detection is automatic, from
__cpp_impl_reflection— nothing about the C++17build changes.
Tests
test_classes.hppaddsBOOST_OPENMETHOD_TEST_CLASSES, which expands toBOOST_OPENMETHOD_CLASSESin C++17 and to nothing under reflection. Tests thatare not about class registration use it and add a trailing
BOOST_OPENMETHOD_CLASSES_IN(::), so a C++26 run exercises reflection-basedregistration across the whole suite: the classes go unregistered and every test
still has to pass. Tests that check what happens when a class is not
registered keep
BOOST_OPENMETHOD_CLASSESand putexplicit_class_registrationin their registry.test_reflection.cppcovers the scan itself.Build
BOOST_OPENMETHOD_ENABLE_REFLECTION=ONprobes for-std=c++26and-std=c++26 -freflection, and applies whichever works per target (not throughCMAKE_CXX_FLAGS— CMake probes the compiler beforeCMAKE_CXX_STANDARDtakes effect, and GCC rejects
-freflectionunder any other standard).<toolset>gcc,<cxxstd>26:<cxxflags>-freflection.reflectionjob builds and runs the suite with GCC 16.Verified locally in both configurations: C++17/clang 153/153, and C++26
reflection (g++-16
-freflection) 148/148.