To determine if a function exists for a function, you can use the following:
template <typename...Ts>
using void_t = void;
void fn(int);
struct X {};
template <typename T, typename = void_t<decltype(fn(std::declval<T>()))>>
void fn2(T) { }
void test() {
fn2(int(1));
}
Now, is there a way to determine if a fn(T)
type exists T
?
Example:
void test2() {
fn2(X());
}
The reason for this is to define an exception operation so that I can define fn2()
in order to avoid an ambiguity error.
source
share