This site has 50+ post about the topic, several 'detection patterns' have had their successes through various epochs. With C++20 we should see quite some simplifications here.
So, what are the current best practices of detecting
F( int )
is defined rather than any F
that takes an int via (an implicit) conversion.Basically requires expressions:
// 1
bool exists = requires(Sig &sig) { sig = thefunction; }
// 2
bool exists = requires(A a) { thefunction(a); }
// 2B
bool exists = requires(C &c, A a) { c.thefunction(a); }
Sig
should be:
using Sig = RV (*) (Args); // A
using Sig = RV (Class::*) (Args); // B
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.