Considering how the comma expression in a decltype() trailing return type can be used to check if a function can be applied:
template <class A>
auto f(A a) -> decltype(check_if_possible(a), return_type(a))
How can I negate the part before the comma to exclude cases in which check_if_possible(a) is defined?
Context:
f() is an overloaded function for different A. I want to resolve an ambiguous overload between two implementations. One of them uses check_if_possible(a), the other works in cases where this cannot be applied to a.
Edit:
Using std::enable_if and related things is welcome as well, but I would like to avoid additional helper functions / templates, because there are several functions similar to f() with different enable criteria.
If this is not possible, then that is an answer as well ;)
I don't know a way, but...
I usually write a
f()function for both cases that demand a couple off_helper()functions receiving an additional argument.For example
Observe the last argument:
0, it's aintThen you can write the
check_if_possible()version, receiving an additionalintand a generic version, always enabled, receiving an additional
longThis way, when
Asupportcheck_if_possible(), bothf_helper()are enabled but the specific version is preferred because0is aint, the specific version receive an additionalint(exact match) and the generic an additionallong(intis convertible tolongbut isn't an exact match).When
Adoesn't supportcheck_if_possible(), only the genericf_helper()is available.