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;