File size

File size

File size

File size

File size

527.2 MB

C++ does not provide facilities for directly expressing what a function template requires of its set of parameters. This is a problem that manifests itself as poor error messages, obscure bugs, lack of proper overloading, poor specification of interfaces, and maintenance problems.

Many have tried to remedy this (in many languages) by adding sets of requirements, commonly known as "concepts." Many of these efforts, notably the C++0x concept design, have run into trouble by focusing on the design of language features.

This talk presents the results of an effort to first focus on the design of concepts and their use; Only secondarily, we look at the design of language features to support the resulting concepts. We describe the problem, our approach to a solution, give examples of concepts for the STL algorithms and containers, and finally show an initial design of language features. We also show how we use a library implementation to test our design.

So far, this effort has involved more than a dozen people, including the father of the STL, Alex Stepanov, but we still consider it research in progress rather than a final design. This design has far fewer concepts than the C++0x design and far simpler language support. The design is mathematically well founded and contains extensive semantic specifications (axioms).

I really love the ultimate goal that concepts try to address. The goal of being more explicit about what we expect from the code can go a lot way in making templates easier to understand and use correctly (a common source of frustration among my co-workers).

Where I think it becomes a bit difficult to cope with (ex: try to explain to my co-workers) is when we start composing a lot of very primitive concepts as Mr. Stroustrup addressed. It can lead to quite an explosion of concepts when we're composing them from concepts as primitive as "Assignable", "Copyable", "LessThanComparable", or combinations of those.

I actually think if the goal was a bit more modest by eliminating the 'requires' keyword and just sticking to the basic form that does not allow concepts to be composed:

Note that I did not even attempt to define a concept for Value here because I haven't come up with a good concept or name for that yet (EqualComparable?), and I think that's fine. We solved at least part of the problem and better defined the iterator argument's requirements and this solution can grow over time.

I really think something like this might have a better chance of being adopted and slowly flourish as it's not an all-or-nothing kind of approach. It can be applied in the areas where the concepts being applied will very concisely apply the necessary constraints (i.e., without the need for composing numerous concepts).

I think the main problem with concepts was that it was too grand in scope. Initially it appeared to be affecting every aspect of how the STL was described by the standard. If it's treated more like an optional feature to gradually work our way towards better expressing the intentions of the code -- something applied only in the areas where it very clearly and concisely expresses intent with higher-level concepts that have already very clearly been established (InputIterator, BidirectionalIterator, Number, etc.), I think that would be a perfectly fine start. It doesn't have to solve everything in the beginning.

Where do we get to see the concepts getting implemented strictly using C++11 language and library features? We will prefer a simple library to start using it right away.

We were referring to the famous paper "A Concept Design for the STL" by Dr. Bjarne Stroustrup et al., which inspired us to dive into Origin C++ Libraries, which is an implementation using C++11. We ended up collating the ideas with our experiments to put these into work in our book : "Foundation of Algorithms in C++11, Volume 1 : Using And Extending C++11, Boost And Beyond". But to go further, we need a complete set-up for C++11 concepts and Origin libraries are still very incomplete and experimental in nature.Can someone point to a library, which is put to practice? Any pointer will be very helpful.

To be clear, we do not mean "C++ Concepts & Axioms" which (as originally proposed) cannot be fully implemented as a library feature.

For example, the paper "A Concept Design of STL" proposes the following interface for the STL Algorithm "std::copy_backward":

Our work on concept design using C++11 can be seen in Part III of our C++11 Cookbook: "Foundation of Algorithms in C++11, Volume 1(Revised Edition): Using and Extending C++11, Boost And Beyond" is available @amazon:http://www.amazon.com/Foundation-Algorithms-Volume-Revised-Edition/dp/1481965549/

Remove this comment

Remove this thread

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums, or
Contact Us and let us know.