3 ms·
Agreed. They are the compile-time interfaces to templates' compile-time classes (so to speak, though obviously templates aren't limited to classes). I've been w
by afranchuk 6y ago
Agreed. They are the compile-time interfaces to templates' compile-time classes (so to speak, though obviously templates aren't limited to classes). I've been wanting them for so long; naturally error messages are better, but documentation will be better integrated/generated too. Just being able to understand what's expected of a templated type in a compile-time verified way is invaluable. I've taken to writing the concepts I'm using in comments (in the concept syntax) and can't wait to start uncommenting them.
- ncmncm 6y agoReally, 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.