Book description
Modern C++ Designis an important book. Fundamentally,
it demonstrates ‘generic patterns’ or ‘pattern
templates’ as a powerful new way of creating extensible
designs in C++–a new way to combine templates and patterns
that you may never have dreamt was possible, but is. If your work
involves C++ design and coding, you should read this book. Highly
recommended.
–Herb Sutter
What’s left to say about C++ that hasn’t already
been said? Plenty, it turns out.
–From the Foreword by John Vlissides
In Modern C++ Design, Andrei Alexandrescu opens new vistas for C++ programmers. Displaying extraordinary creativity and programming virtuosity, Alexandrescu offers a cutting-edge approach to design that unites design patterns, generic programming, and C++, enabling programmers to achieve expressive, flexible, and highly reusable code.
This book introduces the concept of generic components–reusable design templates that produce boilerplate code for compiler consumption–all within C++. Generic components enable an easier and more seamless transition from design to application code, generate code that better expresses the original design intention, and support the reuse of design structures with minimal recoding.
The author describes the specific C++ techniques and features that are used in building generic components and goes on to implement industrial strength generic components for real-world applications. Recurring issues that C++ developers face in their day-to-day activity are discussed in depth and implemented in a generic way. These include:
Policy-based design for flexibility
Partial template specialization
Typelists–powerful type manipulation structures
Patterns such as Visitor, Singleton, Command, and Factories
Multi-method engines
For each generic component, the book presents the fundamental problems and design options, and finally implements a generic solution.
In addition, an accompanying Web site, http://www.awl.com/cseng/titles/0-201-70431-5, makes the code implementations available for the generic components in the book and provides a free, downloadable C++ library, called Loki, created by the author. Loki provides out-of-the-box functionality for virtually any C++ project.
Get a value-added service! Try out all the examples from this book at www.codesaw.com. CodeSaw is a free online learning tool that allows you to experiment with live code from your book right in your browser.
0201704315B11102003
Table of contents
- Title Page
- Copyright Page
- The C++ In-Depth Series
- Contents
- Foreword by Scott Meyers
- Foreword by John Vlissides
- Preface
- Acknowledgments
-
Part I: Techniques
-
1. Policy-Based Class Design
- 1.1. The Multiplicity of Software Design
- 1.2. The Failure of the Do-It-All Interface
- 1.3. Multiple Inheritance to the Rescue?
- 1.4. The Benefit of Templates
- 1.5. Policies and Policy Classes
- 1.6. Enriched Policies
- 1.7. Destructors of Policy Classes
- 1.8. Optional Functionality Through Incomplete Instantiation
- 1.9. Combining Policy Classes
- 1.10. Customizing Structure with Policy Classes
- 1.11. Compatible and Incompatible Policies
- 1.12. Decomposing a Class into Policies
- 1.13. Summary
-
2. Techniques
- 2.1. Compile-Time Assertions
- 2.2. Partial Template Specialization
- 2.3. Local Classes
- 2.4. Mapping Integral Constants to Types
- 2.5. Type-to-Type Mapping
- 2.6. Type Selection
- 2.7. Detecting Convertibility and Inheritance at Compile Time
- 2.8. A Wrapper Around type_info
- 2.9. NullType and EmptyType
- 2.10. Type Traits
- 2.11. Summary
-
3. Typelists
- 3.1. The Need for Typelists
- 3.2. Defining Typelists
- 3.3. Linearizing Typelist Creation
- 3.4. Calculating Length
- 3.5. Intermezzo
- 3.6. Indexed Access
- 3.7. Searching Typelists
- 3.8. Appending to Typelists
- 3.9. Erasing a Type from a Typelist
- 3.10. Erasing Duplicates
- 3.11. Replacing an Element in a Typelist
- 3.12. Partially Ordering Typelists
- 3.13. Class Generation with Typelists
- 3.14. Summary
- 3.15. Typelist Quick Facts
-
4. Small-Object Allocation
- 4.1. The Default Free Store Allocator
- 4.2. The Workings of a Memory Allocator
- 4.3. A Small-Object Allocator
- 4.4. Chunks
- 4.5. The Fixed-Size Allocator
- 4.6. The SmallObjAllocator Class
- 4.7. A Hat Trick
- 4.8. Simple, Complicated, Yet Simple in the End
- 4.9. Administrivia
- 4.10. Summary
- 4.11. Small-Object Allocator Quick Facts
-
1. Policy-Based Class Design
-
Part II: Components
-
5. Generalized Functors
- 5.1. The Command Design Pattern
- 5.2. Command in the Real World
- 5.3. C++ Callable Entities
- 5.4. The Functor Class Template Skeleton
- 5.5. Implementing the Forwarding Functor::operator()
- 5.6. Handling Functors
- 5.7. Build One, Get One Free
- 5.8. Argument and Return Type Conversions
- 5.9. Handling Pointers to Member Functions
- 5.10. Binding
- 5.11. Chaining Requests
- 5.12. Real-World Issues I: The Cost of Forwarding Functions
- 5.13. Real-World Issues II: Heap Allocation
- 5.14. Implementing Undo and Redo with Functor
- 5.15. Summary
- 5.16. Functor Quick Facts
-
6. Implementing Singletons
- 6.1. Static Data + Static Functions != Singleton
- 6.2. The Basic C++ Idioms Supporting Singletons
- 6.3. Enforcing the Singleton’s Uniqueness
- 6.4. Destroying the Singleton
- 6.5. The Dead Reference Problem
- 6.6. Addressing the Dead Reference Problem (I): The Phoenix Singleton
- 6.7. Addressing the Dead Reference Problem (II): Singletons with Longevity
- 6.8. Implementing Singletons with Longevity
- 6.9. Living in a Multithreaded World
- 6.10. Putting It All Together
- 6.11. Working with SingletonHolder
- 6.12. Summary
- 6.13. SingletonHolder Class Template Quick Facts
-
7. Smart Pointers
- 7.1. Smart Pointers 101
- 7.2. The Deal
- 7.3. Storage of Smart Pointers
- 7.4. Smart Pointer Member Functions
- 7.5. Ownership-Handling Strategies
- 7.6. The Address-of Operator
- 7.7. Implicit Conversion to Raw Pointer Types
- 7.8. Equality and Inequality
- 7.9. Ordering Comparisons
- 7.10. Checking and Error Reporting
- 7.11. Smart Pointers to const and const Smart Pointers
- 7.12. Arrays
- 7.13. Smart Pointers and Multithreading
- 7.14. Putting It All Together
- 7.15. Summary
- 7.16. SmartPtr Quick Facts
-
8. Object Factories
- 8.1. The Need for Object Factories
- 8.2. Object Factories in C++: Classes and Objects
- 8.3. Implementing an Object Factory
- 8.4. Type Identifiers
- 8.5. Generalization
- 8.6. Minutiae
- 8.7. Clone Factories
- 8.8. Using Object Factories with Other Generic Components
- 8.9. Summary
- 8.10. Factory Class Template Quick Facts
- 8.11. CloneFactory Class Template Quick Facts
- 9. Abstract Factory
- 10. Visitor
-
11. Multimethods
- 11.1. What Are Multimethods?
- 11.2. When Are Multimethods Needed?
- 11.3. Double Switch-on-Type: Brute Force
- 11.4. The Brute-Force Approach Automated
- 11.5. Symmetry with the Brute-Force Dispatcher
- 11.6. The Logarithmic Double Dispatcher
- 11.7. FnDispatcher and Symmetry
- 11.8. Double Dispatch to Functors
- 11.9. Converting Arguments: static_cast or dynamic_cast?
- 11.10. Constant-Time Multimethods: Raw Speed
- 11.11. BasicDispatcher and BasicFastDispatcher as Policies
- 11.12. Looking Forward
- 11.13. Summary
- 11.14. Double Dispatcher Quick Facts
-
5. Generalized Functors
- Appendix. A Minimalist Multithreading Library
- Bibliography
- Index
Product information
- Title: Modern C++ Design: Generic Programming and Design Patterns Applied
- Author(s):
- Release date: February 2001
- Publisher(s): Addison-Wesley Professional
- ISBN: None
You might also like
video
Modern C++ Design Patterns
This course provides beginning to intermediate C++ developers with the knowledge required for up-to-date C++ programming. …
book
Modern C++ Programming with Test-Driven Development
If you program in C++ you've been neglected. Test-driven development (TDD) is a modern software development …
book
C++ Software Design
Good software design is essential for the success of your project, but designing software is hard …
book
API Design for C++
API Design for C++ provides a comprehensive discussion of Application Programming Interface (API) development, from initial …