3 ms·
Can concepts be used like traits in non-generic code? Which is to say, can it be used as a type name of a variable or function argument? Because there seems to
by lobster_johnson 10y ago
Can concepts be used like traits in non-generic code? Which is to say, can it be used as a type name of a variable or function argument? Because there seems to be a lot of overlap between a concept and a pure virtual class, both of which define function signatures. But if concepts are only for templates, and you still have to use pure virtual classes to express traits, that seems like a missed opportunity to me. But I may be missing some nuance here.
- steveklabnik 10y agoIt's not clear to me; I didn't see it in this pdf but might have missed it.
- matt_d 10y ago> can it be used as a type name of a variable or function argument? If I understand correctly, placeholders may work for this. This use is described in the "Programming with placeholders" section of the "Introducing concepts" article: https://accu.org/index.php/journals/2157 https://accu.org/index.php/journals/2157 The remaining articles in Andrew Sutton's C++ concepts series are pretty good, too; so, just in case anyone is interested, here are the links: - "Defining Concepts" - https://accu.org/index.php/journals/2198 https://accu.org/index.php/journals/2198 - "Overloading with Concepts" - https://accu.org/index.php/journals/2316 https://accu.org/index.php/journals/2316
- lobster_johnson 10y agoIf I understand the first article about placeholders correctly, concepts are indeed intended to be used where you can use ordinary types, just like traits. That looks really cool, if it ends up in the standard.