Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents


Part Six: Extending C++

Above all else, the most powerful aspect of C++ is its extensibility. The most clear and persuasive example of this is the Standard Template Library (STL), which has changed the way most of us use C++ and has become a major component of the C++ standard library. Covering the extensibility of STL would be a book in itself.

However, the STL is just one example. There are myriad ways in which this extensibility can manifest, and in this final part we'll cover just a few of the more interesting ones.

The first of the five chapters, Chapter 31, Return Value Lifetime, goes into the subject in some depth, via the implementation of a conceptually simple library component. We end up incorporating into the solution a practical treatment of several of the issues covered earlier in the book, including threading, statics, and efficiency. We end up finding a real value in garbage-collected systems that even the grand skeptics—such as me—cannot refute.

Chapter 32, Memory, looks at the various memory mechanisms in C/C++, and addresses the traditional, and often vexing, choice between speed and flexibility. It also looks at the costs and benefits of compile-time and run time allocator selection, and discusses ways in which all the different schemes may be optimally combined.

The next chapter, Chapter 33, Multidimensional Arrays, demonstrates several techniques for addressing the limited facilities in C++ for dynamically variable multidimensional arrays. As we so often find, there are imperfections with providing such multidimensional arrays as class types, but we learn that by wearing the hairshirt, and being good subscripting boys and girls, we can have our cake and eat it, too.

Chapter 34, Functors and Ranges, investigates some of the less usable aspects of the STL and modern C++ idioms, and describes some of the early stages of a project—RangeLib—in which I'm involved with some other C++ expansionists. The range concept is essentially a way of dealing with a range as a single entity rather than the now classic asymmetric pair. We'll take a look at some of the early work on the RangeLib project to see just how powerful this simple concept can be.[1]

[1] Later versions of the RangeLib may well find their way onto the CD, and are also available from the RangeLib site at http://rangelib.org/.

The final chapter, Chapter 35, Properties, describes how C++ can be made to support properties in a time- and space-efficient manner. We'll see just how far we can stretch the language into some dark corners in our quest for high-level concepts at low (speed and memory) cost. This is one of my favorite chapters in the book,[2] and it really does speak strongly to how powerful and adaptable this language really is.

[2] If you think that's because it's the biggest, and I'm just an old windbag, well...there may some merit in that.



      Previous section   Next section