Not quite sure if my terminology is 100% correct, so here's the code:
template<class... Ts>
struct Empty { };
int main() {
using T = Empty<int, double>;
// How to check if T "contains" double?
return 0;
}
So this is specifically for types that accept multiple template types. Also this would ideally be at compile time. Bonus points if it doesn't need an object of the type.
The closest I was able to get (with help) was this:
template <class check, class T, class... U>
constexpr bool contains_type(){
if constexpr (std::is_same_v<T, check>)
return true;
else if constexpr (sizeof...(U) > 0)
return contains_type<check, U...>();
else
return false;
}
template <class check, template<class> class TypeToCheck, class... T>
constexpr bool does_obj_contain_type(TypeToCheck<T...>) {
if constexpr (sizeof...(T) > 0)
return contains_type<check, T...>();
else
return false;
}
constexpr bool does_contain_double = does_obj_contain_type<double>(T{});
That contains C++ syntax I've never before seen, but it works. Would be neat if it wouldn't require the T{} object. And maybe look a bit saner.