Chapter 23. Customizing and Extending the STL

The previous two chapters have shown that the STL is a powerful general-purpose collection of containers and algorithms. The information covered so far should be sufficient for most applications. The STL, however, is much more flexible and extensible than the previous chapters have demonstrated. For example, you can apply iterators to input and output streams; write your own containers, algorithms, and iterators; and even specify your own memory allocation schemes for containers to use. This chapter provides a taste of these advanced features, primarily through the development of a new STL container: the hashmap. The specific contents of the chapter include:

  • A closer look at allocators

  • Iterator adapters

  • Extending the STL

    • Writing algorithms

    • Writing containers: a hash map implementation

    • Writing Writing iterators: a hash map iterator implementation

This chapter is not for the faint of heart! The contents delve into some of the most complicated and syntactically confusing areas of the C++ language. If you're happy with the basic STL containers and algorithms from the previous two chapters, you can skip this one. However, if you really want to understand the STL, not just use it, give this chapter a chance. Make sure that you're comfortable with the template material in Chapter 11 before reading this chapter.

Allocators

Recall from Chapter 21 that every STL container takes an Allocator type as a template parameter, for which the default will usually ...

Get Professional C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.