Concepts and C++ Templates

| 0 Comments
The slides from Herb Sutter's C++ Futures talk (TLN309) at this year's PDC refer to "Concepts" in C++ templates; for me this is a much more useful addition than the auto keyword repurposing. I'm sure this is something that would make Chris Baus happy...

I did a little Googling and came up with this paper which describes the proposal in detail. It looks pretty good.

In summary a concept that is required by a template can be defined in code and the compiler can check that the type supplied to the template adheres to the concept and should be able to produce more useful error messages when it doesn't. It takes the implicit concept specification that current templates use and makes it explicit. Think of it as being an interface (abstract class) that the template uses but that the type being used in the template doesn't have to derive from. It means you can clearly specify the requirements of a template, in code, and have the compiler enforce them.

Leave a comment