mr-edd.co.uk :: horsing around with the C++ programming language

Google tech talk videos on C++

[10th June 2007]

I haven't written anything in a while because I've been patching up the opaque_iterator library. It's not far from done, bit it's proving very tricky to iron out all the corner cases.

Anyway, to fill the void I thought I'd quickly mention some of the videos that I've come across on the web over the last month or two that I found interesting in one way or another.

A summary of C++09

The next version of the C++ standard is due to emerge in 2009. Lawrence Crowl summarises the features likely to make it in to the next revision of the C++ standard.

His presentation includes notes on:

The syntax proposed for automatic return types is somewhat funky, i.e. the return type comes after the arguments list with an arrow (->) in between.

I'm still undecided about garbage collection, too. In particular, I don't understand why it can't be implemented as a smart-pointer library[1], rather than making somewhat far-reaching changes to the language.

I'm worried that the people requesting it are coming from garbage collected languages and don't understand:

  1. what RAII and deterministic destruction gives you over GC
  2. and how easy memory management really is in C++ if you take the time to learn how to do it

Don't get me wrong, I'm not anti-GC. There are some situations where using GC makes things much easier, such as cyclic graph-like data structures. But there's usually a better way and I don't know if the extra complication is justified.

I'm very much looking forward to concepts so I can wave goodbye to page-long error messages.

Initialization lists

Bjarne Stroustrup explaining some of the problems surrounding the standardisation of initializer lists for arbitrary types e.g. std::vector<int> v = {1, 2, 3};.

It's surprising the number of issues that crop up. It's certainly a feature that I thought was needed, but after reading this I'm a little worried about the complexity/consistency trade-off that this feature implies.

I'm still leaning towards wanting them, though.

Template Concepts

Here's one of Douglas Gregor running through how template concepts are going to work in the next version of the C++ standard.

Essentially they're a way of specifying explicit constraints on parameters to template classes an functions. It's not uncommon to get error messages that are many pages long when you pass the wrong template parameter to instantiate a template class, or when you call a template function whose arguments don't quite have the semantics that the function expects (try calling std::sort() on a pair of std::list<int>::iterators, for example).

I'm really looking forward to this feature as I do a lot of stuff with templates in my code and generic/meta-programming continues to gain momentum among C++ developers.

I'm some what weary of adding a new sub-language to specify concept expectations and constraints, but it will apparently stay very simple. Another thing that worries me is increased compile times. Template code is time consuming enough as it is.

Douglas Gregor has a weblog about the experimental implementation of concepts in GCC. When I get a free weekend, I may try compiling it for Windows.

Concurrency and threads

Another video of Lawrence Crowl going in to some more detail about the plans for threads in C++.

People are writing threaded code in C++ right now, but as of this moment we have to rely on compiler-specific documentation to find out what guarantees we have when multiple threads are used in a given program. For example, are function-level static variables initialised atomically? Ans: it depends on your compiler. The C++ standard says nothing on the matter.

This is because the C++ standard is written in terms of a single threaded virtual machine. So support for threading in the standard is something that's really needed.

There's nothing particularly unexpected in the presentation, but it's worth a look if you're interested in creating multi-threaded applications (and you should be!). Most the time is spent discussing the low-level aspects of threads in the language. On the face of it, the minimal library features will be similar, if not identical to those in boost.

Footnotes
  1. garbage collection has been implemented at least once as a library to my knowledge. See William Kempf's gc_ptr. Part 1 and Part 2 []

Comments

Pierre Phaneuf

[22/06/2008 at 16:22:00]

You might find the C++ Stylistics and How To Design A Good API and Why it Matters interesting as well.

(optional)
(optional)
(required, hint)

Links can be added like [this one -> http://www.mr-edd.co.uk], to my homepage.
Phrases and blocks of code can be enclosed in {{{triple braces}}}.
Any HTML markup will be escaped.