Overview of Standard Library Components
A class is considered for the C++ standard library when it is helpful to almost every C++ programmer, novices and experts alike.
Why the Standard Library Is Selective
Imagine you maintain a shared toolbox that thousands of people will carry around and rely on. Every tool you add makes the box heavier, more crowded, and harder for a newcomer to understand. So you need a way to decide what earns a place. The C++ standard library faces exactly this problem. Any class that enters it becomes something every C++ program may depend on, so the decision to include a class is a serious one.
Before reading on, think about what you would want a shared, widely used class to be like. Would you want it to solve a narrow problem for a handful of experts, or a common problem for almost everyone? Would you want it to be fast and lean, or wrapped in extra cost? Would you want it to be easy to pick up on the first day? Keep your answers in mind, because the three criteria the library uses are built around exactly these concerns.
The Three Inclusion Tests
A candidate class is considered for the C++ standard library when it is helpful to almost every C++ programmer, novices and experts alike. Three tests describe how a class gets in. Each test asks a different question about the same candidate, so a class must answer all three well rather than excelling at only one.
The three criteria are: the class must be helpful to almost every C++ programmer; it must be provided in a general form without significant overhead compared with a simpler version of the same facility; and simple uses of it must be easy to learn, judged relative to how complicated the underlying task is.
Tracing a Proposal Through the Criteria
The best way to make the criteria concrete is to run a candidate through them one test at a time. The example below uses an invented proposal, not a class named in the source. Follow the reasoning step by step, and notice that the order of the checks matters: a proposal that fails an early test does not need the later tests applied to it.
Read the diagram from top to bottom. The first question is breadth: if the proposal serves only a specialist group, it is rejected immediately. If it passes, the second question is cost: if a general form would impose significant overhead beyond a simpler version of the same facility, it is rejected. Only a proposal that clears all three tests is accepted, and the third test is the one that checks whether ordinary use stays approachable.
Walking Through a Hypothetical Proposal
Judging a proposed image-tag class
A contributor proposes a class called ImageTagger. It bundles together many specialized options for tagging medical imaging scans, and its simplest use requires configuring about twenty settings before any tag can be created. It is fast and lean once configured. Does it fit the criteria?
- 1Test 1: broad usefulness
The class serves medical imaging specialists. Most C++ programmers would never need it, so it fails the test of being helpful to almost every C++ programmer. Because this test comes first, the proposal is rejected here and the remaining tests do not need to be applied to decide the outcome.
- 2Suppose the proposal is reshaped
Now imagine a revised proposal, a general tagging class that any program can use to attach labels to data. Its breadth is now much better, so it moves on to the second test.
- 3Test 2: general form without overhead
The revised class adds a constant cost to every use, even when a plain, simpler version of the same facility would avoid that cost. This is significant overhead, so the proposal fails the second test.
- 4Test 3: easy first use
Had the class passed test two, we would check whether a simple use is easy to learn. Its simplest use would still require many setup decisions, which is hard for a newcomer relative to a task that is not especially complicated.
Neither version is accepted. The specialist version fails breadth at the first test, and the reshaped version fails the overhead test. The example shows that a proposal can fail at any stage, and that an early failure makes later tests unnecessary.
What the Library Is For
The three tests describe how a class gets in. The purpose statement describes what the library as a whole is for. According to the source, the C++ standard library supplies the most common fundamental data structures, along with the fundamental algorithms that operate on those structures. The library is therefore built around two partners: containers that hold data, and procedures that work on that data.
The concept map shows the relationship between the parts. The purpose branch names the two partners the source describes: data structures that hold data, and algorithms that act on them. The inclusion branch is a separate gatekeeping process that decides which classes join this collection at all. The criteria protect the purpose: a class is admitted because it is broadly useful, not because it is merely interesting.
Mistakes Learners Make With the Criteria
Common mistake Treating power or sophistication as the main reason a class belongs in the library
What it looks likeArguing that a class should be included because it handles a very difficult special case very well.
Why it failsThe first criterion is about breadth of audience. Sophistication aimed at a specialist group does not satisfy the requirement that the class be helpful to almost every C++ programmer.
Do this insteadAsk first who will use the class, and whether almost every C++ programmer would find it helpful.
Common mistake Assuming the general form is always better because it is more flexible
What it looks likeAccepting a proposal that is maximally general even though a simpler version of the same facility runs noticeably faster.
Why it failsThe second criterion explicitly rejects significant overhead compared with a simpler version of the same facility.
Do this insteadCompare the general form against the simpler version and check whether the extra cost is significant.
Common mistake Judging ease of learning by the simplest task rather than relative to the underlying complexity
What it looks likeCalling a class hard to learn because a sophisticated task needs more explanation than a trivial one.
Why it failsThe third criterion is judged relative to how complicated the underlying task is, so an intricate task can reasonably need more to learn.
Do this insteadMeasure simple uses against the difficulty of the task they perform, not against the easiest possible task.
Common mistake Applying the tests in a random order instead of stopping at the first failure
Judging Your Own Proposal
A colleague proposes a new class that is extremely useful to game engine developers working on physics simulation, but that most application programmers would never need. Its simplest use is easy to learn, and it adds no overhead beyond a simpler alternative. Using the three criteria in order, decide whether the class should be accepted into the C++ standard library, and state which test decides the outcome.
Hints
- Start with the first criterion. Ask whether the class is helpful to almost every C++ programmer, not only to a specialist group.
- Notice that the proposal satisfies the second and third criteria. Those passes do not rescue a proposal that fails an earlier test.
- A proposal that fails the first test is rejected there, so the later tests never become the deciding factor.
Connecting the Criteria to the Library's Purpose
Taken together, the criteria and the purpose explain why the standard library is deliberately selective. The library exists to supply the most common fundamental data structures and the fundamental algorithms that operate on them. A class that would not be helpful to nearly every programmer, that carries significant overhead, or that is hard to start using works against that purpose, so the three tests keep the collection focused on what the broad community needs.
Key Takeaways
- A class is considered for the C++ standard library when it is helpful to almost every C++ programmer, novices and experts alike.
- The three criteria are broad usefulness, a general form without significant overhead compared with a simpler version, and simple uses that are easy to learn relative to the task's complexity.
- The criteria are applied in order, and a proposal that fails an early test is rejected without needing the later tests.
- The library's purpose is to supply the most common fundamental data structures together with the fundamental algorithms that operate on them.