did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201704310

Modern C++ Design Generic Programming and Design Patterns Applied

by ;
  • ISBN13:

    9780201704310

  • ISBN10:

    0201704315

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2001-02-13
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $64.99 Save up to $6.50
  • Digital
    $58.49
    Add to Cart

    DURATION
    PRICE

Supplemental Materials

What is included with this book?

Summary

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.

 

Author Biography

Andrei Alexandrescu is the author of the award-winning book Modern C++ Design (Addison-Wesley, 2001) and is a columnist for C/C++ Users Journal.



Table of Contents

Foreword xi
Scott Meyers
Foreword xv
John Vlissides
Preface xvii
Acknowledgments xxi
Part I Techniques 1(96)
Policy-Based Class Design
3(20)
The Multiplicity of Software Design
3(1)
The Failure of the Do-It-All Interface
4(1)
Multiple Inheritance to the Rescue?
5(1)
Templates Bring Hope
6(1)
Policies and Policy Classes
7(5)
Enriched Policies
12(1)
Destructors of Policy Classes
12(1)
Optional Functionality Through Incomplete Instantiation
13(1)
Combining Policy Classes
14(2)
Customizing Structure with Policy Classes
16(1)
Compatabile and Noncompatible Policies
17(2)
Decomposing a Class in Policies
19(1)
Summary
20(3)
Techniques
23(26)
Compile-Time Assertions
23(3)
Partial Template Specialization
26(2)
Local Classes
28(1)
Mapping Integral Constants to Types
29(2)
Type-to-Type Mapping
31(2)
Type Selection
33(1)
Detecting Convertibility and Inheritance at Compile Time
34(3)
A Wrapper Around type_info
37(2)
NullType and EmptyType
39(1)
Type Traits
40(6)
Summary
46(3)
Typelists
49(28)
The Need for Typelists
49(2)
Defining Typelists
51(1)
Linearizing Typelist Creation
52(1)
Calculating Length
53(1)
Intermezzo
54(1)
Indexed Access
55(1)
Searching Typelists
56(1)
Appending to Typelists
57(1)
Erasing a Type from a Typelist
58(1)
Erasing Duplicates
59(1)
Replacing an Element in a Typelist
60(1)
Partially Ordering Typelists
61(3)
Class Generation with Typelists
64(10)
Summary
74(1)
Typelist Quick Facts
75(2)
Small-Object Allocation
77(20)
The Default Free Store Allocator
78(1)
The Workings of a Memory Allocator
78(2)
A Small-Object Allocator
80(1)
Chunks
81(3)
The Fixed-Size Allocator
84(3)
The Small ObjAllocator Class
87(2)
A Hat Trick
89(3)
Simple, Complicated, Yet Simple in the End
92(1)
Administrivia
93(1)
Summary
94(1)
SmallObjectAllocator Quick Facts
94(3)
Part II Components 97(204)
Generalized Functors
99(30)
The Command Design Pattern
100(2)
Command in the Real World
102(1)
C++ Callable Entities
103(1)
The Functor Class Template Skeleton
104(4)
Implementing the Forwarding Functor::operator ()
108(2)
Handling Functors
110(2)
Build One, Get One Free
112(2)
Argument and Return Type Conversions
114(1)
Handling Pointers to Member Functions
115(4)
Binding
119(3)
Chaining Requests
122(1)
Real-World Issues I: The Cost of Forwarding Functions
122(2)
Real-World Issues II: Heap Allocation
124(1)
Implementing Undo and Redo with Functor
125(1)
Summary
126(1)
Functor Quick Facts
126(3)
Implementing Singletons
129(28)
Static Data + Static Functions != Singleton
130(1)
The Basic C++ Idioms Supporting Singleton
131(1)
Enforcing the Singleton's Uniqueness
132(1)
Destroying the Singleton
133(2)
The Dead Reference Problem
135(2)
Addressing the Dead Reference Problem (I): The Phoenix Singleton
137(2)
Addressing the Dead Reference Problem (II): Singletons with Longevity
139(3)
Implementing Singletons with Longevity
142(3)
Living in a Multithreaded World
145(3)
Putting It All Together
148(5)
Working With SingletonHolder
153(2)
Summary
155(1)
SingletonHolder Class Template Quick Facts
155(2)
Smart Pointers
157(40)
Smart Pointers 101
157(1)
The Deal
158(2)
Smart Pointers' Storage
160(1)
Smart Pointer Member Functions
161(2)
Ownership-Handling Strategies
163(7)
The Address-of Operator
170(1)
Implicit Conversion of Raw Pointer Type
171(2)
Equality and Inequality
173(5)
Ordering Comparisons
178(3)
Checking and Error Reporting
181(1)
Smart Pointers to const and const Smart Pointers
182(1)
Arrays
183(1)
Smart Pointers and Multithreading
184(3)
Putting It All Together
187(7)
Summary
194(1)
SmartPtr Quick Facts
194(3)
Object Factories
197(22)
The Need for Object Factories
198(2)
Object Factories in C++: Classes and Objects
200(1)
Implementing an Object Factory
201(5)
Type Identifiers
206(1)
Generalization
207(3)
Minutiae
210(1)
Clone Factories
211(4)
Using Object Factories with Other Generic Components
215(1)
Summary
216(1)
Factory Class Template Quick Facts
216(1)
CloneFactory Class Template Quick Facts
217(2)
Abstract Factory
219(16)
The Architectural Role of Abstract Factory
219(4)
A Generic Abstract Factory Interface
223(3)
Implementing AbstractFactory
226(2)
A Prototype-Based Abstract Factory Implementation
228(5)
Summary
233(1)
AbstractFactory and ConcreteFactory Quick Facts
233(2)
Visitor
235(28)
Visitor Basics
235(7)
Overloading: The Catch-All Function
242(1)
An Implementation Refinement: The Acyclic Visitor
243(5)
A Generic Implementation of Visitor
248(7)
Back to the ``Cyclic'' Visitor
255(3)
Hooking Variations
258(2)
Summary
260(1)
Visitor Generic Component Quick Facts
261(2)
Multimethods
263(38)
What Are Multimethods?
264(1)
When Are Multimethods Needed?
264(1)
Double Switch-on-Type: Brute Force
265(3)
The Brute-Force Approach Automated
268(5)
Symmetry with the Brute-Force Dispatcher
273(3)
The Logarithmic Double Dispatcher
276(6)
FnDispatcher and Symmetry
282(1)
Double Dispatch to Functors
282(3)
Converting Arguments: static_cast or dynamic_cast?
285(5)
Constant-Time Multimethods: Raw Speed
290(3)
BasicDispatcher and BasicFastDispatcher as Policies
293(1)
Looking Forward
294(2)
Summary
296(1)
Double Dispatcher Quick Facts
297(4)
Appendix A Minimalist Multithreading Library 301(10)
A.1 A Critique of Multithreading
302(1)
A.2 Loki's Approach
303(1)
A.3 Atomic Operations on Integral Types
303(2)
A.4 Mutexes
305(1)
A.5 Locking Semantics in Object-Oriented Programming
306(2)
A.6 Optional volatile Modifier
308(1)
A.7 Semaphores, Events, and Other Good Things
309(1)
A.8 Summary
309(2)
Bibliography 311(2)
Index 313

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

You might be holding this book in a bookstore, asking yourself whether you should buy it. Or maybe you are in your employers library, wondering whether you should invest time in reading it. I know you dont have time, so Ill cut to the chase. If you have ever asked yourself how to write higher-level programs in C++, how to cope with the avalanche of irrelevant details that plague even the cleanest design, or how to build reusable components that you dont have to hack into each time you take them to your next application, then this book is for you. Imagine the following scenario. You come from a design meeting with a couple of printed diagrams, scribbled with your annotations. Okay, the event type passed between these objects is not char anymore; its int. You change one line of code. The smart pointers to Widget are too slow; they should go unchecked. You change one line of code. The object factory needs to support the new Gadget class just added by another department. You change one line of code. You changed the design. Compile. Link. Done. Well, there is something wrong with this scenario, isnt there? A much more likely scenario is this: You come from the meeting in a hurry because you have a pile of work to do. You fire a global search. You perform surgery on code. You add code. You introduce bugs. You remove the bugs . . . thats the way a programmers job is, right? Although this book cannot possibly promise you the first scenario, it is nonetheless a resolute step in that direction. It tries to present C++ as a newly discovered language for software architects. Traditionally, code is the most detailed and intricate aspect of a software system. Historically, in spite of various levels of language support for design methodologies (such as object orientation), a significant gap persisted between the blueprints of a program and its code because the code must take care of the ultimate details of the implementation and of many ancillary tasks. The intent of the design is, more often than not, dissolved in a sea of quirks. This book presents a collection of reusable design artifacts, called generic components,together with the techniques that make them possible. These generic components bring their users the well-known benefits of libraries, but in the broader space of system architecture. The coding techniques and the implementations provided focus on tasks and issues that traditionally fall in the area of design, activities usually done beforecoding. Because of their high level, generic components make it possible to map intricate architectures to code in unusually expressive, terse, and easy-to-maintain ways. Three elements are reunited here: design patterns, generic programming, and C++. These elements are combined to achieve a very high rate of reuse, both horizontally and vertically. On the horizontal dimension, a small amount of library code implements a combinatorialand essentially open-endednumber of structures and behaviors. On the vertical dimension, the generality of these components makes them applicable to a vast range of programs. This book owes much to design patterns, powerful solutions to ever-recurring problems in object-oriented development. Design patterns are distilled pieces of good designrecipes for sound, reusable solutions to problems that can be encountered in manycontexts. Design patterns concentrate on providing a suggestive lexicon for designs to be conveyed. They describe the problem, a time-proven solution with its variants, and the consequences of choosing each variant of that solution. Design patterns go above and beyond anything a programming language, no matter how advanced, could possibly express. By following and combining certain design patterns, the components presented in this book tend to address a large category of concrete problems. Generic programming is a paradigm that focuses on abstracting types to a narrow collection of functional requirements and on implementing algorithms in terms of these requirements. Because algorithms define a strict and narrow interface to the types they operate on, the same algorithm can be used against a wide collection of types. The implementations in this book use generic programming techniques to achieve a minimal commitment to specificity, extraordinary terseness, and efficiency that rivals carefully handcrafted code. C++ is the only implementation tool used in this book. You will not find in this book code that implements nifty windowing systems, complex networking libraries, or clever logging mechanisms. Instead, you will find the fundamental components that make it easy to implement all of the above, and much more. C++ has the breadth necessary to make this possible. Its underlying C memory model ensures raw performance, its support for polymorphism enables object-oriented techniques, and its templates unleash an incredible code generation machine. Templates pervade all the code in the book because they allow close cooperation between the user and the library. The user of the library literally controls he way code is generated, in ways constrained by the library. The role of a generic component library is to allow user-specified types and behaviors to be combined with generic components in a sound design. Because of the static nature of the technique used, errors in mixing and matching the appropriate pieces are usually caught during compile time. This books manifest intent is to create generic componentspreimplemented pieces of design whose main characteristics are flexibility, versatility, and ease of use. Generic components do not form a framework. In fact, their approach is complementarywhereas a framework defines interdependent classes to foster a specific object model, generic components are lightweight design artifacts that are independent of each other, yet can be mixed and matched freely. They can be of great help in implementingframeworks. Audience The intended audience of this book falls into two main categories. The first category is that of experienced C++ programmers who want to master the most modern library writing techniques. The book presents new, powerful C++ idioms that have surprising capabilities, some of which werent even thought possible. These idioms are of great help in writing high-level libraries. Intermediate C++ programmers who want to go a step further will certainly find the book useful, too, especially if they invest a bit of perseverance. Although pretty hard-core C++ code is sometimes presented, it is thoroughly explained. The second category consists of busy programmers who need to get the job done without undergoing a steep learning investment. They can skim the most intricate details of implementation and concentrate on usingthe provided library. Each chapter has an introductory explanation and ends with a Quick Facts section. Programmers will find these features a useful reference in understanding and using the components. The components can be understood in isolation, are very powerful yet safe, and are a joy to use. You need to have a solid working experience with C++ and, above all, the desire to learn more. A degree of familiarity with templates and the Standard Template Library (STL) is desirable. Having an acquaintance with design patterns (Gamma et al. 1995) is recommended but not mandatory. The patterns and idioms applied in the book are described in detail.

Rewards Program