Can we detect member function template
, variable template
, class
/struct
/union template
or alias template
without knowing amount, or nature of template
/non-template
parameters?
When I try to think about this, nothing really comes to my mind. But let's have structure with member function template:
struct foo
{
// Really random. Let's assume we don't know this declaration, just the name "bar"
template <class T, std::size_t N, class... Args>
void bar(T a, T b, T(&c)[N], Args const& ...);
};
How do I check if the foo::bar
template exists?
Instantiation-based type traits don't apply here, because (theoretically) we don't have knowledge of which parameters we should use, in what order and how many of them. Maybe some magic lookup method would be appropriate? Or maybe it's just impossible?
When searching, I found this question, but solutions in the answers require knowledge about nature of template
.
Here is my first failed attempt for detecting struct template
:
struct foo
{
template<class T>
struct bar { };
};
template <class T, class = void>
struct has_template_bar : std::false_type
{ };
template <class T>
struct has_template_bar <T, void> : std::true_type
{
template<template<class...> class tplt_tplt = T::bar> // Invalid default argument
struct placebo
{ };
};