-- EDIT --
googling I've found an interesting solution that give me inspiration to avoid recursion and to avoid a lot of warnings
So you can define a wrapper of type
template <typename>
struct wrapT
{ };
and a wrapper for type and integer that inherit from the wrapper for type
template <typename T, std::size_t>
struct wrapTI : public wrapT<T>
{ };
Next you can define a foo
class that recursively inherit from wrapTI
template <typename T,
typename = std::make_index_sequence<std::tuple_size<T>::value>>
struct foo;
template <typename ... Ts, std::size_t ... Is>
struct foo<std::tuple<Ts...>, std::index_sequence<Is...>>
: public wrapTI<Ts, Is>...
{ };
Now is_unique
can be something like
template <typename ... Ts>
static constexpr bool isUnique
= ( ... && std::is_convertible<foo<std::tuple<Ts...>>, wrapT<Ts>>::value );
The point is that foo<Ts...>
can be converted to wrapT<T>
only if foo<Ts...>
inherit one time (and only one time) from wrapT<T>
, that is if T
is present one time (and only one time) in Ts...
.
The following is a full compiling example
#include <tuple>
#include <type_traits>
template <typename>
struct wrapT
{ };
template <typename T, std::size_t>
struct wrapTI : public wrapT<T>
{ };
template <typename T,
typename = std::make_index_sequence<std::tuple_size<T>::value>>
struct foo;
template <typename ... Ts, std::size_t ... Is>
struct foo<std::tuple<Ts...>, std::index_sequence<Is...>>
: public wrapTI<Ts, Is>...
{ };
template <typename ... Ts>
static constexpr bool isUnique
= ( ... && std::is_convertible<foo<std::tuple<Ts...>>, wrapT<Ts>>::value );
int main ()
{
static_assert( true == isUnique<int, long, long long> );
static_assert( false == isUnique<int, long, long long, int> );
}