Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions include/boost/openmethod/preamble.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,16 +1126,17 @@ struct with_aux<Policies> {
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<class Policies, class Policy, class... MorePolicies>
struct with_aux<Policies, Policy, MorePolicies...> {
using replace = mp11::mp_replace_if_q<
Policies,
mp11::mp_bind_front_q<
mp11::mp_quote_trait<std::is_base_of>, typename Policy::category>,
Policy>;
using in_category = mp11::mp_bind_front_q<
mp11::mp_quote_trait<std::is_base_of>, typename Policy::category>;
using replace_or_add = std::conditional_t<
std::is_same_v<replace, Policies>, mp11::mp_push_back<Policies, Policy>,
replace>;
mp11::mp_any_of_q<Policies, in_category>::value,
mp11::mp_replace_if_q<Policies, in_category, Policy>,
mp11::mp_push_back<Policies, Policy>>;
using type = typename with_aux<replace_or_add, MorePolicies...>::type;
};

Expand Down
8 changes: 8 additions & 0 deletions test/test_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ static_assert(std::is_same_v<
static_assert(
std::is_same_v<registry<foo1, bar1>::without<bar>, registry<foo1>>);

// Adding a policy the registry already has changes nothing.
static_assert(std::is_same_v<registry<foo1>::with<foo1>, registry<foo1>>);
static_assert(std::is_same_v<
registry<foo1, bar1>::with<bar1, foo2>, registry<foo2, bar1>>);
static_assert(std::is_same_v<
default_registry::with<policies::fast_perfect_hash>,
default_registry::registry_type>);

BOOST_AUTO_TEST_CASE(test_registry) {
using namespace policies;

Expand Down
Loading