Boost.Hana  1.7.1
Your standard library for metaprogramming
boost::hana::detail::has_duplicates< T > Struct Template Reference

Description

template<typename ... T>
struct boost::hana::detail::has_duplicates< T >

Returns whether any of the Ts are duplicate w.r.t. hana::equal.

In particular, this does not check whether all of the Ts are unique as types, but rather whether they are unique when compared as hana::equal(std::declval<T>(), std::declval<U>()). This assumes the comparison to return an IntegralConstant that can be explicitly converted to bool.

Note
Since this utility is mostly used in assertions to check that there are no duplicates in a sequence, we expect it to return false most of the time (otherwise we will assert). Hence, this implementation is biased towards the fact that we will have to compare every pair of elements in most cases, and it does not try to be lazy.
Todo:
This implementation is O(n^2). We could do it in O(n), but that would require a more elaborate setup including storage with O(1) lookup (which could be based on a compile-time hash). If we implement such storage for associative sequences, we could use it to optimize this.