From 3ed749ed983ce9cfd3cfb86e6d6e3f75536c4812 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sat, 28 Nov 2026 11:47:45 -0500 Subject: [PATCH] fix: registry::with

appended a policy the registry already had with_aux decided whether a policy's category was already present by comparing the policy list before and after replacing it. When the new policy is the one already there, the replacement leaves the list unchanged, so it was taken for "absent" and appended a second copy: registry::with was registry, and default_registry::with failed the "two or more stateful policies ... share the same nested `state` type" static_assert. Ask whether the category is present with mp_any_of instead. Co-Authored-By: Claude Opus 5.5 --- include/boost/openmethod/preamble.hpp | 15 ++++++++------- test/test_policies.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/boost/openmethod/preamble.hpp b/include/boost/openmethod/preamble.hpp index 9cb75027..5da9583c 100644 --- a/include/boost/openmethod/preamble.hpp +++ b/include/boost/openmethod/preamble.hpp @@ -1126,16 +1126,17 @@ struct with_aux { using type = Policies; }; +// Whether a policy is already in the category is asked directly. Comparing the +// list before and after the replacement cannot tell "absent" from "replaced by +// itself", and appended a second copy of a policy the registry already had. template struct with_aux { - using replace = mp11::mp_replace_if_q< - Policies, - mp11::mp_bind_front_q< - mp11::mp_quote_trait, typename Policy::category>, - Policy>; + using in_category = mp11::mp_bind_front_q< + mp11::mp_quote_trait, typename Policy::category>; using replace_or_add = std::conditional_t< - std::is_same_v, mp11::mp_push_back, - replace>; + mp11::mp_any_of_q::value, + mp11::mp_replace_if_q, + mp11::mp_push_back>; using type = typename with_aux::type; }; diff --git a/test/test_policies.cpp b/test/test_policies.cpp index cd3b7f8a..67b9f68f 100644 --- a/test/test_policies.cpp +++ b/test/test_policies.cpp @@ -66,6 +66,14 @@ static_assert(std::is_same_v< static_assert( std::is_same_v::without, registry>); +// Adding a policy the registry already has changes nothing. +static_assert(std::is_same_v::with, registry>); +static_assert(std::is_same_v< + registry::with, registry>); +static_assert(std::is_same_v< + default_registry::with, + default_registry::registry_type>); + BOOST_AUTO_TEST_CASE(test_registry) { using namespace policies;