STL Pocket Reference: Containers, Iterators, and Algorithms (Pocket Reference (OReilly))

The Standards committee decided to recognize that fact, and to start working on library extensions even before work on a new Standard began. We couldn't publish an official Standard on new library components, but what we could do, and what we did decide to do, was publish the work on library extensions in the form of a technical report. This report isn't "normative," in the jargon of standards bureaucracy, which means that compiler vendors don't have to include any of these new libraries to conform to the Standard. What it does is provide guidance to those vendors who do want to include them.

In the meantime it gives us a head start on describing new library components in "standardese," gives us experience implementing and using new libraries, and will eventually make it easier to incorporate them into the next official Standard. The idea of a library extensions technical report was first proposed at the Copenhagen meeting. The committee's library working group which I chair began discussing specific ideas for new library extensions at the next meeting and started to solicit proposals.

The first extension proposals were accepted at the Santa Cruz meeting, and the last at the Kona meeting. Since then, the committee has been filling gaps, and fixing bugs and corner cases. Most of the remaining steps are bureaucratic.

  • Best C++ books for beginners | Online Books Review?
  • The Technical Report on C++ Library Extensions!
  • The further adventures of Mrs Trimbles magic teapot.;
  • The Solomon Kane, And Other Stories:17 Stories by Robert E. Howard.
  • Join Kobo & start eReading today.
  • The Cock and Anchor.
  • STL Pocket Reference!

There may be some minor changes before it is officially finalized, but the substantive work is now essentially complete; see http: Like the Standard, it contains classes and functions and type requirements. The style of specification in the TR is deliberately similar to the style in the Standard, because it is expected that much of what's in the TR will eventually become part of a future Standard.

For the obvious reason: Someday there may be a namespace std:: Everything in it, by definition, is experimental; it's there to get user and implementor experience. The only requirement is that these data structures provide access to their elements via iterators. Conversely, new algorithms, provided that they access the objects they operate on only through the iterator interface, can work with all existing and yet-to-exist STL data structures. For additional flexibility, STL algorithms parameterize some of their behavior in terms of "function objects" that can be invoked using function call syntax.

The STL was designed to be extensible, and people immediately extended it. Some of the most obvious gaps to be filled were in the containers. The STL includes three containers for variable-sized sequences of elements: It also includes set and dictionary classes based on balanced trees: Most other languages, including Perl, Python, and Java, have hash-based dictionaries. The only real reason was historical. Individual vendors filled that gap. Something that's provided by different vendors in not-quite-compatible versions is a natural candidate for standardization, so the technical report, at last, includes hash tables.

TR1 hash tables have many specialized features, but in simple cases they're used much the same way as the standard associative containers. In Listing One , the name of this class might give you pause. Unfortunately, that history is the biggest reason for using a different name. It's impossible to make TR1 hash tables compatible with all previous STL hash table implementations because they aren't compatible with each other.

Since the committee had to use a different interface, it felt that the right decision was to use a different name to go with it. The unordered associative containers, like all STL containers, are homogeneous. All of the elements in an std:: But the Standard also has one heterogeneous container: Pairs are useful whenever two things need to be packaged together. One common use is for functions that return multiple values. The second part of the return value is a flag that tells you whether you did actually insert a new element or whether there was already one there with the same key, and the first part points to either the preexisting element or the newly inserted one.

Pairs are useful for packaging multiple values, so long as "multiple" means two. But that seems like an arbitrary restriction. Just as functions sometimes need to return more than one value, so they sometimes need to return more than two. In mathematics, an n -tuple is an ordered collection of n values; pairs are the special case where n is restricted to be 2. TR1 introduces a new heterogeneous container template, std:: Implementing tuple requires some sophisticated programming techniques, but using it couldn't be simpler.

Up to some limit, but the limit should be large.

Best C++ books for beginners

On all implementations that I know of, it's at least Instead, you can just write:. Now that we have tuple , which provides a dramatic improvement in usability, these clumsy workarounds might disappear. What's important is that these types are a common vocabulary, so that two parts of a program, written independently of each other, can use them to communicate. The library extension technical report adds a number of other useful utility components of this nature.

One problem that appears in most programs is managing resource lifetimes.

18.2: Iterators

If you allocate memory or open a network socket, when does that memory get deallocated and when does the socket get closed? Two common solutions to that problem are automatic variables "resource acquisition is initialization," or RAII and garbage collection. However, neither is appropriate in every circumstance. RAII works best when resource lifetime is statically determined and tied to the program's lexical structure, while garbage collection works better for memory than for other kinds of resources, and in any case is sometimes overkill.

A third alternative, one that has been reinvented many times, is reference-counted smart pointers. The basic idea behind reference-counted pointers is straightforward: The difference is that the wrapper class can instrument its basic operations, its constructors and destructor and assignment operators, so that it can keep track of how many owners a particular object has. You can confirm this by doing a simple test with a class that logs its constructors and destructors. In Listing Two , the two pointers, p1 and p2, both point to the same A object, and both of those pointers are destroyed when they go out of scope.

Naturally, real examples are more complicated than this test case. As with tuple and string , it gives programs a common vocabulary: If I had written my own custom reference-counting class, that wouldn't have been true. That's not as trivial as it might seem! Reference-counted pointers don't completely remove the possibility of resource management bugs; some discipline by programmers is needed.

There are two potential problems. First, suppose that two objects are pointing to each other. They form a cycle, and will eventually cause a memory leak. Trying to dereference p1 will probably make your program crash. In my opinion, that was the right design decision. These two sources of bugs go together because people commonly mix reference-counted pointers and raw pointers precisely to avoid cycles.

Reward Yourself

This is a perfectly valid technique, especially if you resist the temptation to use a raw pointer for that "something else. TR1 includes other primitives as well as smart pointers, including components that make it easier to use functions and function objects. This language will give you the foundation you need to become a successful programmer.

You will learn the key differences between classical polymorphism and generic programming, the foundation of the STL. You will also learn how to use the various algorithms and containers in the STL to suit your programming needs.

Chapter 18: The Standard Template Library

Here you will learn about algebraic types such as std:: An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use. Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.

  • STL Pocket Reference - O'Reilly Media.
  • What is Kobo Super Points?;
  • 18.1: Predefined function objects?

A final game project at the end of the book draws together everything you've learned. The pros and cons of braced initialization, noexcept specifications, perfect forwarding, and smart pointer make functions The relationships among std:: Learning a programming language can seem like a daunting task.

You may have looked at coding in the past, and felt it was too complicated and confusing.

Calaméo - O'Reilly - Algorithms in a Nutshell ()

In a matter of no time, you will be writing code like a professional. It is a great language to learn whether you have never written a line of code in your life, or are a seasoned developer. We take you step-by-step through writing your very first program, explaining each portion of code as we go along. We guide you through choosing a compiler and editor, as well as common pitfalls beginners should avoid. Reference Manual This book serves as a teaching guide and also a reference manual to accompany you through this wonderful world of programming. This book serves as a teaching guide and also a reference manual to accompany you through this wonderful world of programming.

What This Book Offers Detailed Descriptions Each topic is broken down into small manageable sections where each concept is explained in detail. We look at the different variations and types available, what the various return values mean and even how to avoid common errors. We break examples down into their basic workings, and provide the output for you to compare to your own results.

C/C++ Recent Articles

Proper Syntax We focus on the specific syntax in each topic, as well as alternative variations and how each functions. Have you ever wanted to become a programmer? If you answered "yes", this book is made for you. You will learn the most popular computer languages to make any program you want.

  • Amazon Store.
  • Amazon Store | League of Professional System Administrators.
  • Words of Wilmington.
  • Symptomatische Homöopathie für Katzen: Homöopathische Hausapotheke (German Edition);

Here is what's inside: An introduction of what a program really is. A lot of programs examples that you can do right now! Marc Rawen, the author of this book, will guide you each step of the way. This is your chance create any program you want. So start your training now and achieve the goals that you have. This book will show you how to do it precisely.

The Basics Lesson 1: Getting Started Lesson 2: Using Variables, Declaring Constants Lesson 4: Managing Arrays and Strings Lesson 5: Working with Expressions, Statements, and Operators Lesson 6: Controlling Program Flow Lesson 7: Organizing Code with Functions Lesson 8: Classes and Objects Lesson Implementing Inheritance Lesson Operator Types and Operator Overloading Lesson Casting Operators Lesson More STL Lesson Understanding Function Objects Lesson STL Algorithms Lesson Stack and Queue Lesson Understanding Smart Pointers Lesson Exception Handling Lesson Going Forward Part VI: Binary and Hexadecimal Appendix B: Operator Precedence Appendix D: The three languages are often confusingly similar.

Here are just some of the time-consuming tasks this book contains practical solutions for: An Active Learning Approach. With over 30 years combined teaching experience the authors understand potential pitfalls students face and aim to keep the language simple, straightforward, and conversational.