Modern C++ Design: Generic Programming and Design Patterns Applied / Edition 1

Paperback (Print)
Buy New
Buy New from BN.com
$52.23
Used and New from Other Sellers
Used and New from Other Sellers
from $33.00
Usually ships in 1-2 business days
(Save 49%)
Other sellers (Paperback)
  • All (14) from $33.00   
  • New (8) from $46.01   
  • Used (6) from $33.00   

Overview

Modern C++ Design is 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

Read More Show Less

Editorial Reviews

Booknews
Presents a collection of reusable design artifacts, called generic components, together with the techniques that make them possible. The author describes techniques for policy-based design, partial template specialization, typelists, and local classes, then goes on to implement generic components for smart pointers, object factories, functor objects, the Visitor design pattern, and multimethod engines. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780201704310
  • Publisher: Addison-Wesley
  • Publication date: 2/13/2001
  • Series: C++ in Depth Series
  • Edition description: New Edition
  • Edition number: 1
  • Pages: 323
  • Sales rank: 369,787
  • Product dimensions: 7.36 (w) x 9.12 (h) x 0.76 (d)

Meet the Author

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.

Read More Show Less

Read an Excerpt

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 before coding. 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 implementing frameworks.

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 using the 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. However, this book is not a pattern bookit does not attempt to treat patterns in full generality. Because patterns are presented from the pragmatic standpoint of a library writer, even readers interested mostly in patterns may find the perspective refreshing, if constrained.

Loki

The book describes an actual C++ library called Loki. Loki is the god of wit and mischief in Norse mythology, and the authors hope is that the librarys originality and flexibility will remind readers of the playful Norse god. All the elements of the library live in the namespace Loki. The namespace is not mentioned in the coding examples because it would have unnecessarily increased indentation and the size of the examples. Loki is freely available; you can download it from http://www.awl.com/cseng/titles/0-201-70431-5.

Except for its threading part, Loki is written exclusively in standard C++. This, alas, means that many current compilers cannot cope with parts of it. I implemented and tested Loki using Metrowerks CodeWarrior Pro 6.0 and Comeau C++ 4.2.38, both on Windows. It is likely that KAI C++ wouldnt have any problem with the code, either. As vendors release new, better compiler versions, you will be able to exploit everything Loki has to offer.

Lokis code and the code samples presented throughout the book use a popular coding standard originated by Herb Sutter. Im sure you will pick it up easily. In a nutshell,

Classes, functions, and enumerated types look LikeThis.

Variables and enumerated values look likeThis.

Member variables look likeThis_.

Template parameters are declared with class if they can be only a user-defined type, and with typename if they can also be a primitive type.

Organization

The book consists of two major parts: techniques and components. Part I (Chapters 1 to 4) describes the C++ techniques that are used in generic programming and in particular in building generic components. A host of C++-specific features and techniques are presented: policy-based design, partial template specialization, typelists, local classes, and more. You may want to read this part sequentially and return to specific sections for reference.

Part II builds on the foundation established in Part I by implementing a number of generic components. These are not toy examples; they are components of industrial strength used in real-world applications. Recurring issues that C++ developers face in their day-to-day activity, such as smart pointers, object factories, and functor objects, are discussed in depth and implemented in a generic way. The text presents implementations starting from the needs, the fundamental problems. Instead of explaining what a body of code does, the approach of the book is to discuss problems, take design decisions, and implement those decisions gradually.

Chapter 1 presents policiesa C++ idiom that helps in creating flexible designs.

Chapter 2 discusses general C++ techniques related to generic programming.

Chapter 3 implements typelists, which are powerful type manipulation structures.

Chapter 4 introduces an important ancillary tool: a small-object allocator.

Chapter 5 introduces the concept of generalized functors, useful in designs that use the Command design pattern.

Chapter 6 describes Singleton objects.

Chapter 7 discusses and implements smart pointers.

Chapter 8 describes generic object factories.

Chapter 9 treats the Abstract Factory design pattern and provides implementations of it.

Chapter 10 implements several variations of the Visitor design pattern in a generic manner.

Chapter 11 implements several multimethod engines, solutions that foster various trade-offs.

The design themes cover many important situations that C++ programmers have to cope with on a regular basis. I personally consider object factories (Chapter 8) a cornerstone of virtually any quality polymorphic design. Also, smart pointers (Chapter 7) are an important component of many C++ applications, small and large. Generalized functors (Chapter 5) have an incredibly broad range of applications. Once you have generalized functors, many complicated design problems become very simple. The other, more specialized, generic components, such as Visitor (Chapter 10) or multimethods (Chapter 11) have important niche applications and stretch the boundaries of language support.


Read More Show Less

Table of Contents

Foreword by Scott Meyers.

Foreword by John Vlissides.

Preface.

Acknowledgments.

I. TECHNIQUES.

1. Policy-Based Class Design.

The Multiplicity of Software Design.

The Failure of the Do-It-All Interface.

Multiple Inheritance to the Rescue?

Templates Bring Hope.

Policies and Policy Classes.

Enriched Policies.

Destructors of Policy Classes.

Optional Functionality Through Incomplete Instantiation.

Combining Policy Classes.

Customizing Structure with Policy Classes.

Compatible and Noncompatible Policies.

Decomposing a Class in Policies.

Summary.

2. Techniques.

Compile-Time Assertions.

Partial Template Specialization.

Local Classes 28 2.4 Mapping Integral Constants to Types.

Type-to-Type Mapping.

Type Selection.

Detecting Convertibility and Inheritance at Compile Time.

A Wrapper Around type_info.

NullType and EmptyType.

Type Traits.

Summary.

3. Typelists.

The Need for Typelists.

Defining Typelists.

Linearizing Typelist Creation.

Calculating Length.

Intermezzo.

Indexed Access.

Searching Typelists.

Appending to Typelists.

Erasing a Type from a Typelist.

Erasing Duplicates.

Replacing an Element in a Typelist.

Partially Ordering Typelists.

Class Generation with Typelists.

Summary.

Typelist Quick Facts.

4. Small-Object Allocation.

The Default Free Store Allocator.

The Workings of a Memory Allocator.

A Small-Object Allocator.

Chunks.

The Fixed-Size Allocator.

The SmallObjAllocator Class.

A Hat Trick.

Simple, Complicated, Yet Simple in the End.

Administrivia.

Summary.

Small-Object Allocator Quick Facts.

II. COMPONENTS.

5. Generalized Functors.

The Command Design Pattern.

Command in the Real World.

C11 Callable Entities.

The Functor Class Template Skeleton.

Implementing the Forwarding Functor::operator().

Handling Functors.

Build One, Get One Free.

Argument and Return Type Conversions.

Handling Pointers to Member Functions.

Binding.

Chaining Requests.

Real-World Issues I: The Cost of Forwarding Functions.

Real-World Issues II: Heap Allocation.

Implementing Undo and Redo with Functor.

Summary.

Functor Quick Facts.

6. Implementing Singletons.

Static Data + Static Functions != Singleton.

The Basic C11 Idioms Supporting Singleton.

Enforcing the Singleton's Uniqueness.

Destroying the Singleton.

The Dead Reference Problem.

Addressing the Dead Reference Problem (I):.

Addressing the Dead Reference Problem (II):.

Implementing Singletons with Longevity.

Living in a Multithreaded World.

Putting It All Together.

Working With SingletonHolder.

Summary.

SingletonHolder Class Template Quick Facts.

7. Smart Pointers.

Smart Pointers 101.

The Deal.

Smart Pointers' Storage.

Smart Pointer Member Functions.

Ownership-Handling Strategies.

The Address-of Operator.

Implicit Conversion to Raw Pointer Type.

Equality and Inequality.

Ordering Comparisons.

Checking and Error Reporting.

Smart Pointers to const and const Smart Pointers.

Arrays.

Smart Pointers and Multithreading.

Putting It All Together.

Summary.

SmartPtr Quick Facts.

8. Object Factories.

The Need for Object Factories.

Object Factories in C11: Classes and Objects.

Implementing an Object Factory.

Type Identifiers.

Generalization.

Minutiae.

Clone Factories.

Using Object Factories with Other Generic Components.

Summary.

Factory Class Template Quick Facts.

CloneFactory Class Template Quick Facts.

9. Abstract Factory.

The Architectural Role of Abstract Factory.

A Generic Abstract Factory Interface.

Implementing AbstractFactory.

A Prototype-Based Abstract Factory Implementation.

Summary.

AbstractFactory and ConcreteFactory Quick Facts.

10. Visitor.

Visitor Basics.

Overloading: The Catch-All Function.

An Implementation Refinement: The Acyclic Visitor.

A Generic Implementation of Visitor.

Back to the “Cyclic” Visitor.

Hooking Variations.

Summary.

Visitor Generic Component Quick Facts.

11. Multimethods.

What Are Multimethods?

When Are Multimethods Needed?

Double Switch-on-Type: Brute Force.

The Brute-Force Approach Automated.

Symmetry with the Brute-Force Dispatcher.

The Logarithmic Double Dispatcher.

FnDispatcher and Symmetry.

Double Dispatch to Functors.

Converting Arguments: static_cast or dynamic_cast?

Constant-Time Multimethods: Raw Speed.

BasicDispatcher and BasicFastDispatcher as Policies.

Looking Forward.

Summary.

Double Dispatcher Quick Facts.

Appendix A. Minimalist Multithreading Library.

A Critique of Multithreading.

Loki's Approach.

Atomic Operations on Integral Types.

Mutexes.

Locking Semantics in Object-Oriented Programming.

Optional volatile Modifier.

Semaphores, Events, and Other Good Things.

Summary.

Bibliography.

Index. 0201704315T04062001

Read More Show Less

Preface

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 newlydiscovered 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 before coding. 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 implementing frameworks.

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 using the 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. However, this book is not a pattern bookit does not attempt to treat patterns in full generality. Because patterns are presented from the pragmatic standpoint of a library writer, even readers interested mostly in patterns may find the perspective refreshing, if constrained.

Loki

The book describes an actual C++ library called Loki. Loki is the god of wit and mischief in Norse mythology, and the authors hope is that the librarys originality and flexibility will remind readers of the playful Norse god. All the elements of the library live in the namespace Loki. The namespace is not mentioned in the coding examples because it would have unnecessarily increased indentation and the size of the examples. Loki is freely available; you can download it from http://www.awl.com/cseng/titles/0-201-70431-5.

Except for its threading part, Loki is written exclusively in standard C++. This, alas, means that many current compilers cannot cope with parts of it. I implemented and tested Loki using Metrowerks CodeWarrior Pro 6.0 and Comeau C++ 4.2.38, both on Windows. It is likely that KAI C++ wouldnt have any problem with the code, either. As vendors release new, better compiler versions, you will be able to exploit everything Loki has to offer.

Lokis code and the code samples presented throughout the book use a popular coding standard originated by Herb Sutter. Im sure you will pick it up easily. In a nutshell,

Classes, functions, and enumerated types look LikeThis.

Variables and enumerated values look likeThis.

Member variables look likeThis_.

Template parameters are declared with class if they can be only a user-defined type, and with typename if they can also be a primitive type.

Organization

The book consists of two major parts: techniques and components. Part I (Chapters 1 to 4) describes the C++ techniques that are used in generic programming and in particular in building generic components. A host of C++-specific features and techniques are presented: policy-based design, partial template specialization, typelists, local classes, and more. You may want to read this part sequentially and return to specific sections for reference.

Part II builds on the foundation established in Part I by implementing a number of generic components. These are not toy examples; they are components of industrial strength used in real-world applications. Recurring issues that C++ developers face in their day-to-day activity, such as smart pointers, object factories, and functor objects, are discussed in depth and implemented in a generic way. The text presents implementations starting from the needs, the fundamental problems. Instead of explaining what a body of code does, the approach of the book is to discuss problems, take design decisions, and implement those decisions gradually.

Chapter 1 presents policiesa C++ idiom that helps in creating flexible designs.

Chapter 2 discusses general C++ techniques related to generic programming.

Chapter 3 implements typelists, which are powerful type manipulation structures.

Chapter 4 introduces an important ancillary tool: a small-object allocator.

Chapter 5 introduces the concept of generalized functors, useful in designs that use the Command design pattern.

Chapter 6 describes Singleton objects.

Chapter 7 discusses and implements smart pointers.

Chapter 8 describes generic object factories.

Chapter 9 treats the Abstract Factory design pattern and provides implementations of it.

Chapter 10 implements several variations of the Visitor design pattern in a generic manner.

Chapter 11 implements several multimethod engines, solutions that foster various trade-offs.

The design themes cover many important situations that C++ programmers have to cope with on a regular basis. I personally consider object factories (Chapter 8) a cornerstone of virtually any quality polymorphic design. Also, smart pointers (Chapter 7) are an important component of many C++ applications, small and large. Generalized functors (Chapter 5) have an incredibly broad range of applications. Once you have generalized functors, many complicated design problems become very simple. The other, more specialized, generic components, such as Visitor (Chapter 10) or multimethods (Chapter 11) have important niche applications and stretch the boundaries of language support.

 



Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 9 Customer Reviews
  • Anonymous

    Posted October 1, 2007

    This book covers it all.

    This book covers all the bases for C++. Although I've been programming for several years now, I always come back to this book to refresh any concepts that have grown hazy. Basic concepts and ideas are always expounded upon, and the reader can easily see how organized and thoughtful the author was in putting together this work.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 28, 2006

    Hidden Treasure

    I picked this up because it said 'generic Programming' on the cover. Wow... I can't stop thinking about it. Now I am starting to see uses for the techniques/idioms shown here in almost everything I do. I cannot stress enough how great this book, and, by extension, the author, is. Take my advice: Buy two copies so you'll have one to refer to after you wear the first one out!!!

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 4, 2001

    An Essential C++ Book

    First came type-safe containers and generic algorithms, and then came traits. Now, thanks to Andrei Alexandrescu¿s ground breaking new book ¿Modern C++ Design,¿ we have policies. Policies provide a means of creating very flexible and extendable libraries with little to no run-time overhead. As an example consider the Singleton pattern. What is the lifetime of the singleton? Should it be destroyed? If so, when? What, if any, threading model should the used by the singleton? Unfortunately, there is no one best answer. The good news is that policies allow the application developer to choose the answer that best fits their needs. Several policies are presented in the book but best of all is the fact that if none of the policies are well suited to the problem at hand, it is remarkably easy to write a new policy that plugs into the library. While it may be tempting to write an entire book on singletons, the book covers a myriad of other topics, including but not limited to, smart pointers, object factories, abstract factories, visitors, and a memory allocator optimized for small objects. Each topic is covered thoroughly and is easy to read and understand. Be forwarded however, the reader must have of strong understanding of C++ template fundamentals. This is not an introductory tutorial on templates. There are a number of books that should be considered ¿must have¿ for all professional C++ programmers and designers. These books include Scott Meyers¿ ¿Effective C++¿ and ¿More Effective C++¿, Herb Sutter¿s ¿Exceptional C++¿, and the ¿Gang of Four¿s¿ ¿Design Patterns.¿ ¿Modern C++ Design¿ is the newest addition to this list.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 21, 2001

    I thought STL is all that templates can do!

    I liked the book from both perspectives: style and content The book is very well written, in a vivacious and logical style. The eventual questions raised in one paragraph are answered in the following ones, so every chapter gave me a very clear understanding of the concept the author wanted to present. The chapters succeed smoothly and in a logical order. The content is amazing; I would dare to call it a revolutionary book because it showed that the designs patterns can be actually implemented without loosing their generality. Before reading the book I lived with the idea that once you begin talking about code, that was it, it was the end, it meant that a design solution was chosen and now it is implemented and nothing follows. No, here the implementation, the code Andrei wrote and explained to us, still remains in the design area because it gives the user the option to model and transform the concept, at compile time, the way he\she needs. I warmly recommend the book to any C++ programmer interested to explore the big potential of templates, but also as a rich source of ideas, and reusable code.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 24, 2001

    Awesome

    no punches pulled. no fluff. straight to the meat. Great book. But take your time, advanced topic abound.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 14, 2001

    Cool book

    This book sets a new standard for library development in C++. A refreshing read, Modern C++ Design fills an empty space that's between theoretical stuff such as generic programming or design patterns, and the real world. The author can explain complex design-related issues and equally complex C++ implementation details with remarkable ease. Although the book builds heavily on Design Patterns, you don't need to read the GoF book first, though some prior exposure to design patterns helps. My only complaint is about typos - they don't affect understandability but can be annoying at times. I recommend this book to any C++ programmer who wants to become a system or library designer.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 13, 2001

    Taking C++ to the next level

    Even after the C++ Standard was published, I thought no significant work on C++ can be possible beyond the STL. Modern C++ Design changed my view on C++ forever. The author uses C++ in a metalinguistic manner to implement not specific designs, but to treat the design process in and by itself. For example, in treating a specific design pattern such as Singleton he doesn't make design decisions. Instead, he provides you with a framework that lets you choose and combine various design decisions. Modern C++ Design is a book on 'designing designs' in C++. I also like the completeness of the work; instead of broad and shallow, the author chose a narrow and deep 'no nonsense' approach. Thus, the chapters on Command, Factory, Singleton, Smart Pointers, Visitor, Multiple Dispatch, really tell the first to last word on their respective subjects in the C++ implementation context. A truly inspirational breakthrough on implementing designs with C++, the book is an instant classic. Highly recommended to anyone who wants to be a C++ expert.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 8, 2001

    An amazing book

    I've been waiting for such a book for the longest time. I was sniffing that C++ templates have a lot of potential, but I never had the insight and creativity to be able to harness that potential. Now finally I found the catalyst in this book. Alexandrescu uses advanced C++ to encapsulate in libraries entire pieces of designs, such as singletons, visitors, double dispatch engines, or object factories. In doing this, he gives you, the developer, default behaviors of world-class quality and room for full customization if you need. The book's no-nonsense approach to reuse of software design is novel and definitely worth looking into. I also enjoyed the style - so much lighter and enjoyable than 'Generative Programming.'

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 31, 2008

    No text was provided for this review.

Sort by: Showing all of 9 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)