Chapter 2. Techniques
This chapter presents a host of C++ techniques that are used throughout the book. Because they are of help in various contexts, the techniques presented tend to be general and reusable, so you might find applications for them in other contexts. Some of the techniques, such as partial template specialization, are language features. Others, such as compile-time assertions, come with some support code.
In this chapter you will get acquainted with the following techniques and tools:
Compile-time assertions
Partial template specialization
Local classes
Mappings between types and values (the Int2Type and Type2Type class templates)
The Select class template, a tool that chooses a type at compile time based on a Boolean condition
Detecting convertibility and inheritance at compile time
TypeInfo, a handy wrapper around std::type_info
Traits, a collection of traits that apply to any C++ type
Taken in isolation, each technique and its support code might look trivial; the norm is five to ten lines of easy-to-understand code. However, the techniques have an important property: They are "nonterminal"; that is, you can combine them to generate higher-level idioms. Together, they form a strong foundation of services that helps in building powerful architectural structures.
The techniques come with examples, so don't expect the discussion to be dry. As you read through the rest of the book, you might want to return to this chapter for reference.
|