Via Slashdot. Bjarne Stroustroup, the "designer and original implementor" of the C++ programming language, gives a look forward at the features most likely to be included in the next version of C++, titled C++0x (possibly one of the worst symbol ever for a programming language version).


I was surprised to learn from this article that the next version of C++ won't likely be ready until 2009. They've been batting around ideas for this version for awhile (the last version of C++ was C++98). On one hand it's great that developers and compiler/IDE implementors will be able to keep up with the new versions of the language. On the other hand, it seems to cast a negative shadow on the slow-moving process when compared to other technologies (like web technologies for instance). After all, a lot happens in 3 years (let alone 11 years) in the technology space.

According to Stroustroup, the committee is made of up volunteers who all have "day jobs", so that explains the pace to some degree. Anyway, I somehow get the feeling that the process is moving at a deliberate pace to give time for the market to absorb changes from the last version to see what worked, what didn't and what needs are out there. I don't think the C++ committee feels they need to compete with other technologies since C++ is so well-established in its very wide niche. This isn't to say that C++ doesn't need an upgrade - I agree with Stroustroup, the overall syntax for generic programming in C++ currently sucks (not a big surprise since, if I understand things correctly, generics were thrown in almost as an after-thought in the original C++ design).

Anyway, the underlying goals of committee are noble:

  • Provide stability and compatibility (with C++98, and, if possible, with C)
  • Prefer standard library facilities to language extensions
  • Make only changes that change the way people think
  • Prefer generality to specialization
  • Support both experts and novices
  • Increase type safety (by providing safe alternatives to currently unsafe facilities)
  • Improve performance and ability to work directly with hardware
  • Fit into the real world

Stroustroup doesn't give away much, since nothing is absolutely firm yet. But here's an example of some code that would align with some of the things he talks about:

Proposed C++0x code:

std::vector<double> vec = { 2.4, 1.1, 9.9 };
for( auto it = vec.begin(); it != vec.end(); ++it) { ... }

Equivalent C++89 code:

std::vector<double> vec;
vec.push_back(2.4);
vec.push_back(1.1);
vec.push_back(9.9);
for( std::vector<double>::iterator it = vec.begin(); it != vec.end(); ++it) { ... }

I know which version I prefer!

The idea of the "auto" is great - it means "figure out which type I need". This is fantastic for iterators like the above example - now if I change my underlying container to a std::list, I don't need to change the iterator type (or write a typedef for it), the compiler will pick up the change automatically. Of course you could use the C++98 version if you want to automatically typecast the iterator to some other type but clearly the "auto" idea makes great sense. Anyway, the idea is to eliminate all that unnecessary typing: Why should I have to do all that typing when vec.begin() returns a std::vector<double>::iterator in the first place? I welcome this addition to the language but it may make some programmers lazier in the long run. I can just see people putting "auto" every place instead of looking up the return types of functions and then getting into trouble with casting operations later - hopefully compiler warnings will keep us in line.

The ability to initialize a user-defined container via a list is less important to me, but it is appreciated since it puts user-defined containers almost on par with arrays and structs.

Stroustroup also mentions the idea of concepts which he describes as a "type of a type". In this facility, you specify within a template declaration what properties a template argument must have in order to be properly used within a template. This is used today, I remember Alexandrescu's Loki library as described in "Modern C++ Design", which uses this heavily. But if I understand Stroustroup here, the proposed where clause would allow for less cryptic compiler error handling up-front and to disambiguate "between templates taking the same number of arguments". I'll be interested to see this one when it's fully baked because, as a C++ geek, I'm obliged to be a fan of generic programming ๐Ÿ˜‰

Stroustroup also mentions many of the libraries he would like to see in the next version of the Standard Template Library (STL). I'd personally like to see all of the following standardized now (that way I wouldn't have to worry about including the correct header files in my projects):

You could make arguments that Filesystem and Spirit are outside the core language principles and should stand as separate libraries, but this is my pet list after all so nyah!


§199 · January 3, 2006 · C++, Software, Technology · · [Print]

2 Comments to “The Next C++”

  1. Jeff Garland says:

    A couple notes on this. There is an implementation of the Concept idea already in GCC done by the team at Indiana Univ. See http://www.osl.iu.edu/~dgregor/ConceptGCC/ . This may not be the form of the final extension, but it certainly brings it to life.

    As for your wishes on the library front: bind and mem_fn are already part of TR1 and hence will start arriving in standard library implemenations soon. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf
    for more details on the these and other TR1 extensions. Of course the next boost is going to ship a version of TR1 using the official titles and interfaces to get you started — just in case it takes awhile for the vendors to catch up ๐Ÿ˜‰

    The library working group is now working on TR2 extensions. Filesystem now has a formal proposal to the library working group that has been well accepted so far:
    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1889.html

    Jeff

  2. Jeff Schiller says:

    Jeff,

    Thanks for the information. Sorry I had your post in the queue so long, but I got to it eventually! ๐Ÿ˜‰