# Test whether a type T is among the types of a tuple

In SO I asked for a way to do it without variadics. I also provided a typical "normal" implementation with variadics :

template <typename V, typename T>
struct Is_in_tuple;

template <typename V, typename T0, typename... T>
struct Is_in_tuple <V, tuple<T0, T...> >
{
static const bool value = Is_in_tuple<V, tuple<T...> >::value;
};

template <typename V, typename... T>
struct Is_in_tuple <V, tuple<V, T...> >
{
static const bool value = true;
};

template <typename V>
struct Is_in_tuple <V, tuple<> >
{
static const bool value = false;
};


I'd like a review on the above code, is it safe / OK / missing something, before I make it my standard way of quering type lists?

-

Since you're implementing a traits-like check, I would typically expect your traits class types to be derived from std::true_type and std::false_type. This is certainly not required, and overall this implementation doesn't bug me. I was slightly surprised to see std::tuple<> called out explicitly, but that doesn't seem to change the overall correctness in any way.
The biggest question I have is how exact you want your type matching to be. Do you require exact type matches like std::is_same<T, U> or usably similar types like std::is_convertible<T, U>? To be concrete, what should Is_in_tuple<decltype(0), std::tuple<unsigned int>>::value be? It would be great to have some unit tests that document this sort of edge case.
The only thing I see wrong with your implementation is by implication: either you must have included some form of using, either using namespace std; or using std::tuple;, or you are dependent on someone else having done so before including this header. While correct use of using is fine, particularly in implementation files or inside functions, I would strongly suggest avoiding it here where it will pollute (or require previous pollution of) the compilation unit of whatever code includes this.
This review sent me down a long path trying to figure out how to implement the above traits check without depending on std::tuple. I finally succeeded, and in doing so, I'm tempted to say that the dependency on std::tuple is another potential mistake. But evaluating whether it's a mistake depends on knowing whether your code uses just std::tuple or other custom variadic template classes. –  Michael Urman May 19 at 0:36