4 ms·
> you can now overload based on concept matching Can you use this to compile-time detect if a class has a particular member function? I've used code like this
by dkersten 6y ago
> you can now overload based on concept matching
Can you use this to compile-time detect if a class has a particular member function?
I've used code like this before, and the implementation has always been a bit of a mess, so I wonder if it can be simplified with concepts:
template <class T> void foo (T& t) {
if constexpr (hasMemberBar<T>()) {
t.bar();
}
}
Currently, I use this to implement hasMemberBar and I wonder if there's a better way now: https://gist.github.com/danielytics/8944b51ca51280fba30baab60a3e9d72 https://gist.github.com/danielytics/8944b51ca51280fba30baab6... Especially something that works without using the preprocessor, while still not needing a new implementation for each member I wish to check for.