Пока мне это удалось сделать это следующим образом (отрывок кода):
Код: Выделить всё
template
// recovers N-th typename from a parameter pack
using get_Nth_type = typename std::tuple_element_t;
template
// recovers N-th value of a corresponding type from a parameter pack
constexpr get_Nth_type get_Nth_value(Ts&&... values) { return std::get(std::forward_as_tuple(std::forward(values)...)); }
template
// concept is valid when all types in a parameter pack are the same
concept all_same = (std::same_as and ...);
static_assert(all_same); // fail
static_assert(all_same); // OK
template
// concept is valid when a type T is among types in a parameter pack Ts
concept any_of = (std::same_as or ...);
template
// compile-time boolean is true when N-th type in a parameter pack is equal to any other type in the pack
constexpr bool any_same_as_Nth_helper(std::integer_sequence) { return ((Js != N && std::same_as) or ...); }
template
// concept is valid when N-th type in a parameter pack is equal to any other type in the pack
concept any_same_as_Nth = (any_same_as_Nth_helper(std::make_integer_sequence()));
static_assert(any_same_as_Nth); // fail
static_assert(any_same_as_Nth); // OK
template
// compile-time boolean is true is valid when any type in a parameter pack Ts contains a duplicate
constexpr bool any_same_helper(std::integer_sequence) { return ((any_same_as_Nth) or ...); }
template
// concept is valid when all types in a parameter pack are unique
concept all_unique = (not any_same_helper(std::make_integer_sequence()));
static_assert(all_unique); // fail
static_assert(all_unique); // fail
static_assert(all_unique); // OK
Может ли кто-нибудь показать мне, как реализовать ту же концепцию, например, со сложностью O(N log(N)) - возможно, используя поиск по двоичному дереву?
Подробнее здесь: https://stackoverflow.com/questions/786 ... are-unique
Мобильная версия