I would like to find out if a type defines a member function with a template argument but the template argument is constrained with SFINAE.
Example I have a type A
with a single function foo
struct A{
template<typename T>
std::enable_if<Condition<T>,ReturnType> foo(T t){ ... }
};
Condition
is some condition e.g. std::is_pos_v
Right now I'm using boost::hana::is_valid
to figure out if a type has a member function like foo()
or foo(int)
but when with template argument I'm lost.
I would like to write something like this
auto has_foo = hana::is_valid([](auto t) -> delctype(hana::traits::declval(t).foo(???)){});
has_foo(hana::type_c<A>); // <-- I want this to return true
The question is what should I put instead of ???
?
It is probably impossible for the compiler to "prove" that a type A
satisfy: "For every type T
which satisfy Condition
there is a member function A::foo(T)
"
So to make it easier for the compiler, I would be happy to at least "prove" that for a type A
holds: "There is a type T
such that there is a member function A::foo(T)
"
Unfortunately, this is still hard in my example because this would require proving that there is a type which satisfy Condition
.
Thus isn't it possible for the purpose of introspection to ignore SFIANE? Then I could pick an arbitrary type and test existence of e.g. A::foo(int)
.
A
) is really a map from some set(given byCondition
). (For me a set is a collection of values of typeT
and the type satisfiesCondition
) – Cammiecammyis_valid
code. I don't see why that wouldn't work unless I misunderstand the question. – Ensiform