A Good Online C++ Standard Library Reference

C++ is a language that lets you express yourself in many ways. One of the ways you can express yourself is with very low-level detail oriented code. The kind that deals with raw character pointers instead of string classes, the kind that has you writing your own linked list instead of using std::list. Many times in C++ programming newsgroups and on gamedev.net we counsel new programmers to use the standard string class, the standard resizable array class and so-on, but they seem completely oblivious to their existence.

There are plenty of good books on the C++ Standard Library, my favorite being “The C++ Standard Library: A Tutorial and Reference” by Nicolai Josuttis. I used this book as the basis for a series of internal training seminars on the C++ Standard Library while I worked at Philips Digital Video Systems.

A rather astonishing thing (astonishing to new C++ programmers anyway) happened after that course was completed. Whole categories of bugs disappeared from our code: string bugs and container bugs in particular. String bugs disappeared because we stopped using raw character arrays and started using std::string and std::wstring. Container bugs disappeared because we stopped writing our own resizable array, linked-list and dictionary containers and started using the standard containers std::vector, std::list and std::map. We also became more productive because we were familiar with the algorithms available to us in the standard library and would be able to take advantage of them in our code when appropriate.

With the addition of Technical Report 1 to C++, whether provided by your compiler vendor as Microsoft is doing or provided by the Boost implementation, there is even more ready-made stuff at your disposal as a C++ programmer. If you are unfamiliar with these facilities, you will be handicapped because they are or will be pervasive in C++ programming environments.

So why are so many programmers unaware of these things? Surely it can’t be for the lack of books because there are plenty around and even my favorite book has been around for a decade. (It would be great to see a second volume by Josuttis that covers TR1.) It can’t be for lack of support in compilers because its been supported by compilers for a long time. Sure, I’ve seen people complain about bugs in the VC6 implementation, but even that was a decade ago. At that time I personally didn’t experience any bugs, so the bugs couldn’t have been pervasive or we would have bumped into them. Still, that was a decade ago and the Standard Library implementation shipping with Visual Studio has corrected those problems. So why the continued ignorance?

My theory is that programmers, particularly new programmers, never go far from their IDE when they are programming. The more difficult something is to use from within the IDE, the less likely it is going to be used. While the implementation of the standard library has improved significantly for Visual Studio, the provided documentation is absolutely horrible. Even as a programmer familiar with the standard library I always have a hard time looking up stuff in Visual Studio. The index entries are atrocious, the layouts of the help pages themselves are inconvenient and the descriptions and examples always leave something to be desired. There’s a reason I recommend people buy a copy of Josuttis and keep it on their desk!

I stumbled across something today, thanks to the wxWidgets wx-users mailing list. The Apache Software Foundation has been building a complete implementation of the C++ Standard Library since 2005 (it doesn’t include anything from TR1). The project is called Apache C++ Standard Library (STDCXX) with the following stated goal:

The goal of the Apache C++ Standard Library is to provide a free implementation of the ISO/IEC 14882 international standard for C++ that enables source code portability and consistent behavior of programs across all major hardware implementations, operating systems, and compilers, open source and commercial alike. An additional goal is to achieve maximum implementation efficiency on each platform by taking advantage of platform-specific high-performance facilities and features which are often unique to the type of hardware, the operating system or the compiler.

The best part is that they provide a complete User Guide and Class Reference for their implementation. Given the scope of the C++ Standard Library, providing that documentation alone is no small achievement. I can’t claim to have exhaustively read every page of their documentation, but from the browsing that I’ve done so far it looks good. Now when I try to help people that are struggling with raw character pointers and trying to homebrew their own containers, I can point them to the particular documentation in the Apache C++ Standard Library, even if they aren’t using that implementation.

2 Responses to “A Good Online C++ Standard Library Reference”

  1. legalize Says:

    A coworker pointed me to the reference at http://www.cplusplus.com/, which also has reference for the C++ Standard Library. This is another one I didn’t know about and I like the concise reference sections that it contains.

    Like


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: