4 ms·
Really, you can now overload based on concept matching, and so tailor implementations according to the family of types passed, analogously to overloading regula
by ncmncm 6y ago
Really, you can now overload based on concept matching, and so tailor implementations according to the family of types passed, analogously to overloading regular functions based on actual types, and overloading templates based on partial matches.
Concepts are a fundamentally powerful tool. Haskell people will recognize them as akin to what they call type classes.
Thus, in P2187 http://wg21.link/p2187 http://wg21.link/p2187 we have conditional swap that, for any small- and simple-enough type, is swapped using CMOV instructions instead of a probably badly-predicted branch. This mechanism works in released Gcc-10 today. (Note that what goes into the Standard Library will probably differ, in details, substantially from P2187R5.)
- 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.