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.

9780201704341

More Exceptional C++ 40 New Engineering Puzzles, Programming Problems, and Solutions

by
  • ISBN13:

    9780201704341

  • ISBN10:

    020170434X

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2001-12-17
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
List Price: $49.99

Summary

The Greek philosopher Socrates taught by asking his students questions--questions designed to guide them and help them draw conclusions from what they already knew, and to show them how the things they were learning related to each other and to their existing knowledge. This method has become so famous that we now call it the "Socratic method." From our point of view as students, Socrates' approach involves us, makes us think, and helps us relate and apply what we already know to new information.

This book takes a page from Socrates, as did its predecessor, Exceptional C++ Sutter00. It assumes you're involved in some aspect of writing production C++ software today, and uses a question-answer format to teach you how to make effective use of standard C++ and its standard library with a particular focus on sound software engineering in modern C++. Many of the problems are drawn directly from experiences I and others have encountered while working with production C++ code. The goal of the questions is to help you draw conclusions from things you already know as well as things you've just learned, and to show how they interrelate. The puzzles will show how to reason about C++ design and programming issues--some of them common issues, some not so common; some of them plain issues, some more esoteric; and a couple because, well, just because they're fun.

This book is about all aspects of C++. I don't mean to say that it touches on every detail of C++--that would require many more pages--but rather that it draws from the wide palette of the C++ language and library features to show how apparently unrelated items can be used together to synthesize novel solutions to common problems. It also shows how apparently unrelated parts of the palette interrelate on their own, even when you don't want them to, and what to do about it. You will find material here about templates and namespaces, exceptions and inheritance, solid class design and design patterns, generic programming and macro magic--and not just as randomized tidbits, but as cohesive Items showing the interrelationships among all of these parts of modern C++.

What's "More?"

More Exceptional C++ continues where Exceptional C++ left off. This book follows in the tradition of the first: It delivers new material, organized in bite-sized Items and grouped into themed sections. Readers of the first book will find some familiar section themes, now including new material, such as exception safety, generic programming, and memory management techniques. The two books overlap in structure and theme, not in content.

Where else does More Exceptional C++ differ? This book has a much stronger emphasis on generic programming and on using the C++ standard library effectively, including coverage of important techniques such as traits and predicates. Several Items provide in-depth looks at considerations to keep in mind when using the standard containers and algorithms; many of these considerations I've not seen covered elsewhere. There's a new section and two appendixes that focus on optimization in single- and multithreaded environments--issues that are now more than ever of practical consequence for development shops writing production code.

Versions of most Items originally appeared in Internet and magazine columns, particularly as Guru of the Week GotW issues #31 to 62, and as print columns and articles I've written for C/C++ Users Journal, Dr. Dobb's Journal, the former C++ Report, and other publications. The material in this book has been significantly revised, expanded, corrected, and updated since those initial versions, and this book (along with its de rigueur errata list available at www.gotw.ca) should be treated as the current and authoritative version of that original material.

What I Assume You Know

I expect that you already know the basics of C++. If you don't, start with a good C++ introduction and overview. Good choices are a classic tome like Bjarne Stroustrup's The C++ Programming Language Stroustrup00, or Stan Lippman and Josee Lajoie's C++ Primer, Third Edition Lippman98. Next, be sure to pick up a style guide such as Scott Meyers' classic Effective C++ books Meyers96 Meyers97. I find the browser-based CD version Meyers99 convenient and useful.

How to Read This Book

Each Item in this book is presented as a puzzle or problem, with an introductory header that resembles the following:

Item #: The Topic of This Puzzle
Difficulty: X

The topic tag and difficulty rating gives you a hint of what you're in for. Note that the difficulty rating is my subjective guess at how difficult I expect most people will find each problem, so you may well find that a "7" problem is easier for you than some "5" problem. Since writing Exceptional C++, I've regularly received e-mail saying that "Item #N is easier (or harder) than that!" It's common for different people to vote "easier!" and "harder!" for the same Item. Ratings are personal; any Item's actual difficulty for you really depends on your knowledge and experience and could be easier or harder for someone else. In most cases, though, you should find the rating to be a good rule-of-thumb guide to what to expect.

You might choose to read the whole book front to back; that's great, but you don't have to. You might decide to read all the Items in a section together because you're particularly interested in that section's topic; that's cool, too. Except where there are what I call a "miniseries" of related problems which you'll see designated as "Part 1," "Part 2," and so on, the Items are pretty independent, and you should feel free to jump around, following the many cross-references among the Items in the book, as well as some references to Exceptional C++. The only guidance I'll offer is that the miniseries are designed to be read consecutively as a group; other than that, the choice is yours.

Namespaces, Typename, References, and Other Conventions

I make quite a few recommendations in this book, and I won't give you guidelines that tell you to do something I don't already do myself. That includes what I do in my own example code throughout this book. I'll also bow to existing practice and modern style, even when it really makes no material difference.

On that note, a word about namespaces: In the code examples, if you see a using-directive at file scope in one example and at function scope in another example a few pages or Items later, there's no deeper reason than that's what felt right and aesthetically pleasing to me for that particular case; for the rationale, turn to Item 40. In the narrative text itself, I've chosen to qualify standard library names with std:: when I want to emphasize that it's the standard facility I'm talking about. Once that's established, I'll generally switch back to using the unqualified name.

When it comes to declaring template parameters, I sometimes come across people who think that writing class instead of typename is old-fashioned, even though there's no functional difference between the two and the standard itself uses class most everywhere. Purely for style, and to emphasize that this book is about today's modern C++, I've switched to using typename instead of class to declare template parameters. The only exception is one place in Item 33, where I quote directly from the standard; the standard says class, so I left it in there.

Unless I call something a "complete program," it's probably not. Remember that the code examples are usually just snippets or partial programs and aren't expected to compile in isolation. You'll usually have to provide some obvious scaffolding to make a complete program out of the snippet shown.

Final

Author Biography

Herb Sutter is the author of three highly acclaimed books, Exceptional C++ Style, Exceptional C++, and More Exceptional C++ (Addison-Wesley). He chairs the ISO C++ standards committee, and is contributing editor and columnist for C/C++ Users Journal. As a software architect for Microsoft, Sutter leads the design of C++ language extensions for .NET programming.



Table of Contents

Foreword
Preface
Generic Programming and the C++ Standard Library
Switching Streams (2 / 10)
Predicates
What remove() Removes (4 / 10)
Predicates
Matters of State (7 / 10)
Extensible Templates: Via Inheritance or Traits? (7 / 10)
Typename (7 / 10)
Containers, Pointers, and Containers That Aren't (5 / 10)
Using Vector and Deque (3 / 10)
Using Set and Map (5 / 10)
Equivalent Code? (5 / 10)
Template Specialization and Overloading (6 / 10)
Mastermind (8 / 10)
Optimization and Performance
Inline (4 / 10)
Lazy Optimization
A Plain Old String (2 / 10)
Lazy Optimization
Introducing Laziness (3 / 10)
Lazy Optimization
Iterators and References (6 / 10)
Lazy Optimization
Multi-Threaded Environments (8 / 10)
Exception Safety Issues and Techniques
Constructor Failures
Object Lifetimes (4 / 10)
Constructor Failures
Absorption? (7 / 10)
Uncaught Exceptions (6 / 10)
An Unmanaged Pointer Problem
Parameter Evaluation (6 / 10)
An Unmanaged Pointer Problem
What About auto_ptr? (8 / 10)
Exception-Safe Class Design
Copy Assignment (7 / 10)
Exception-Safe Class Design
Inheritance (6 / 10)
Inheritance and Polymorphism
Why Multiple Inheritance? (6 / 10)
Emulating Multiple Inheritance (5 / 10)
Multiple Inheritance and the Siamese Twin Problem (4 / 10)
(Im)pure Virtual Functions (7 / 10)
Controlled Polymorphism (3 / 10)
Memory and Resource Management
Using auto_ptr (5 / 10)
Smart Pointer Members
A Problem with auto_ptr (5 / 10)
Smart Pointer Members
Toward a ValuePtr (6 / 10)
Free Functions and Macros
Recursive Declarations (6 / 10)
Simulating Nested Functions (5 / 10)
Preprocessor Macros (4 / 10)
#Definition (4 / 10)
Miscellaneous Topics
Initialization (3 / 10)
Forward Declarations (3 / 10)
Typedef (3 / 10)
Namespaces
Using-Declarations and Using-Directives (2 / 10)
Namespaces
Migrating to Namespaces (4 / 10)
Afterword
Appendixes
Optimizations That Aren't (In a Multithreaded World)
Test Results for Single- versus Multi-Thread-Safe String Implementations
Bibliography
Index020170434XT07022001
Table of Contents provided by Publisher. All Rights Reserved.

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

The Greek philosopher Socrates taught by asking his students questions--questions designed to guide them and help them draw conclusions from what they already knew, and to show them how the things they were learning related to each other and to their existing knowledge. This method has become so famous that we now call it the "Socratic method." From our point of view as students, Socrates' approach involves us, makes us think, and helps us relate and apply what we already know to new information. This book takes a page from Socrates, as did its predecessor,Exceptional C++Sutter00. It assumes you're involved in some aspect of writing production C++ software today, and uses a question-answer format to teach you how to make effective use of standard C++ and its standard library with a particular focus on sound software engineering in modern C++. Many of the problems are drawn directly from experiences I and others have encountered while working with production C++ code. The goal of the questions is to help you draw conclusions from things you already know as well as things you've just learned, and to show how they interrelate. The puzzles will show how to reason about C++ design and programming issues--some of them common issues, some not so common; some of them plain issues, some more esoteric; and a couple because, well, just because they're fun. This book is about all aspects of C++. I don't mean to say that it touches on every detail of C++--that would require many more pages--but rather that it draws from the wide palette of the C++ language and library features to show how apparently unrelated items can be used together to synthesize novel solutions to common problems. It also shows how apparently unrelated parts of the palette interrelate on their own, even when you don't want them to, and what to do about it. You will find material here about templates and namespaces, exceptions and inheritance, solid class design and design patterns, generic programming and macro magic--and not just as randomized tidbits, but as cohesive Items showing the interrelationships among all of these parts of modern C++. What's "More?" More Exceptional C++continues whereExceptional C++left off. This book follows in the tradition of the first: It delivers new material, organized in bite-sized Items and grouped into themed sections. Readers of the first book will find some familiar section themes, now including new material, such as exception safety, generic programming, and memory management techniques. The two books overlap in structure and theme, not in content. Where else doesMore Exceptional C++differ? This book has a much stronger emphasis on generic programming and on using the C++ standard library effectively, including coverage of important techniques such as traits and predicates. Several Items provide in-depth looks at considerations to keep in mind when using the standard containers and algorithms; many of these considerations I've not seen covered elsewhere. There's a new section and two appendixes that focus on optimization in single- and multithreaded environments--issues that are now more than ever of practical consequence for development shops writing production code. Versions of most Items originally appeared in Internet and magazine columns, particularly asGuru of the WeekGotW issues #31 to 62, and as print columns and articles I've written forC/C++ Users Journal,Dr. Dobb's Journal, the formerC++ Report, and other publications. The material in this book has been significantly revised, expanded, corrected, and updated since those initial versions, and this book (along with its de rigueur errata list available at www.gotw.ca ) should be treated as the current and authoritative version of that original material. What I Assume You Know I expect that you already know the basics of C++. If

Rewards Program