From 6060f4e306880fc5bd22362e11c798bfb920db20 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sat, 15 Nov 2025 16:23:23 -0500 Subject: [PATCH 1/2] make initialize and finalize symmetric --- doc/mrdocs.yml | 2 ++ include/boost/openmethod/initialize.hpp | 19 ++++++++++++++++--- include/boost/openmethod/preamble.hpp | 10 ---------- test/test_dispatch.cpp | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/doc/mrdocs.yml b/doc/mrdocs.yml index ea838b46..d1e12688 100644 --- a/doc/mrdocs.yml +++ b/doc/mrdocs.yml @@ -22,6 +22,8 @@ inaccessible-bases: never # implementation-defined: # - 'boost::openmethod::detail::**' exclude-symbols: + - 'boost::openmethod::registry::initialize' + - 'boost::openmethod::registry::finalize' - 'boost::openmethod::boost_openmethod_bases' - 'boost::openmethod::boost_openmethod_registry' diff --git a/include/boost/openmethod/initialize.hpp b/include/boost/openmethod/initialize.hpp index 7f829d84..aa6a6733 100644 --- a/include/boost/openmethod/initialize.hpp +++ b/include/boost/openmethod/initialize.hpp @@ -1657,9 +1657,22 @@ auto registry::finalize(Options... opts) -> void { initialized = false; } -//! Finalize the default registry -inline auto finalize() -> void { - BOOST_OPENMETHOD_DEFAULT_REGISTRY::finalize(); +//! Release resources held by registry. +//! +//! `finalize` may be called to release any resources allocated by +//! @ref registry::initialize. +//! +//! @note +//! A translation unit that contains a call to `finalize` must include the +//! `` header. +//! +//! @tparam Registry The registry to finalize. +//! @tparam Options... Zero or more option types, deduced from the function +//! arguments. +//! @param options Zero or more option objects. +template +inline auto finalize(Options&&... opts) -> void { + Registry::finalize(std::forward(opts)...); } namespace aliases { diff --git a/include/boost/openmethod/preamble.hpp b/include/boost/openmethod/preamble.hpp index edda369a..9f68286d 100644 --- a/include/boost/openmethod/preamble.hpp +++ b/include/boost/openmethod/preamble.hpp @@ -946,16 +946,6 @@ class registry : detail::registry_base { //! @li @ref not_initialized: The registry is not initialized. static void require_initialized(); - //! Releases the resources held by the registry. - //! - //! `finalize` may be called to release any resources allocated by - //! @ref registry::initialize. - //! - //! @note - //! A translation unit that contains a call to `finalize` must include the - //! `` header. - //! - //! @tparam Options A registry. template static void finalize(Options... opts); diff --git a/test/test_dispatch.cpp b/test/test_dispatch.cpp index 780367f5..5cd36396 100644 --- a/test/test_dispatch.cpp +++ b/test/test_dispatch.cpp @@ -339,7 +339,7 @@ BOOST_AUTO_TEST_CASE(simple) { if constexpr (std::is_same_v) { BOOST_TEST( !detail::vptr_vector_vptrs.empty()); - test_registry::finalize(); + finalize(); static_assert(detail::has_finalize_aux< void, test_registry::policy, std::tuple<>>::value); From b82992b09944db23a200b91daf3c48903a464852 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sat, 15 Nov 2025 16:24:41 -0500 Subject: [PATCH 2/2] do not put initialize in aliases --- doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp | 6 +++--- doc/modules/ROOT/examples/shared_libs/indirect_main.cpp | 4 ++-- doc/modules/ROOT/examples/shared_libs/static_main.cpp | 2 +- include/boost/openmethod/initialize.hpp | 4 ---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp b/doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp index c3835939..b74ea6dc 100644 --- a/doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp +++ b/doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp @@ -41,7 +41,7 @@ int main() { // end::unload[] std::cout << "Before loading the shared library.\n"; - initialize(); + boost::openmethod::initialize(); std::cout << "cow meets wolf -> " << meet(*std::make_unique(), *std::make_unique()) @@ -60,7 +60,7 @@ int main() { boost::dll::shared_library lib( boost::dll::program_location().parent_path() / LIBRARY_NAME, boost::dll::load_mode::rtld_now); - initialize(); + boost::openmethod::initialize(); std::cout << "cow meets wolf -> " << meet(*std::make_unique(), *std::make_unique()) @@ -83,7 +83,7 @@ int main() { std::cout << "\nAfter unloading the shared library.\n"; lib.unload(); - initialize(); + boost::openmethod::initialize(); std::cout << "cow meets wolf -> " << meet(*std::make_unique(), *std::make_unique()) diff --git a/doc/modules/ROOT/examples/shared_libs/indirect_main.cpp b/doc/modules/ROOT/examples/shared_libs/indirect_main.cpp index a968f464..555435e0 100644 --- a/doc/modules/ROOT/examples/shared_libs/indirect_main.cpp +++ b/doc/modules/ROOT/examples/shared_libs/indirect_main.cpp @@ -37,7 +37,7 @@ auto main() -> int { using namespace boost::openmethod::aliases; std::cout << "Before loading the shared library.\n"; - initialize(); + boost::openmethod::initialize(); auto gracie = make_unique_virtual(); auto willy = make_unique_virtual(); @@ -53,7 +53,7 @@ auto main() -> int { boost::dll::program_location().parent_path() / LIBRARY_NAME, boost::dll::load_mode::rtld_now); - initialize(); + boost::openmethod::initialize(); std::cout << "cow meets wolf -> " << meet(*gracie, *willy) << "\n"; // run std::cout << "wolf meets cow -> " << meet(*willy, *gracie) << "\n"; // hunt diff --git a/doc/modules/ROOT/examples/shared_libs/static_main.cpp b/doc/modules/ROOT/examples/shared_libs/static_main.cpp index 3f2ae6ae..a285a2a2 100644 --- a/doc/modules/ROOT/examples/shared_libs/static_main.cpp +++ b/doc/modules/ROOT/examples/shared_libs/static_main.cpp @@ -30,7 +30,7 @@ auto make_tiger() -> Animal*; } auto main() -> int { - initialize(); + boost::openmethod::initialize(); std::unique_ptr gracie(new Cow()); std::unique_ptr willy(new Wolf()); diff --git a/include/boost/openmethod/initialize.hpp b/include/boost/openmethod/initialize.hpp index aa6a6733..17098d1f 100644 --- a/include/boost/openmethod/initialize.hpp +++ b/include/boost/openmethod/initialize.hpp @@ -1675,10 +1675,6 @@ inline auto finalize(Options&&... opts) -> void { Registry::finalize(std::forward(opts)...); } -namespace aliases { -using boost::openmethod::initialize; -} - } // namespace boost::openmethod #ifdef _MSC_VER