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)); // works
//fn2(X()); // doesn't work
}
Now, is there a way of detecting if the fn(T)
doesn't exist for type T
?
Example:
void test2() {
//fn2(int(1)); // doesn't work
fn2(X()); // works
}
Aucun commentaire:
Enregistrer un commentaire