Book description
Organized in a practical problem-and-solution format, More Exceptional C++ picks up where the widely acclaimed Exceptional C++ leaves off, providing successful strategies for solving real-world problems in C++. Drawing from years of in-the-trenches experience, Herb Sutter provides tested techniques and practical solutions for programmers designing modern software systems with C++, from small projects to enterprise applications.
Built around forty programming puzzles, More Exceptional C++ helps you understand the rules and issues critical to successful software design and development in C++. New themes included in this sequel place a strong emphasis on generic programming, memory management, and using the C++ standard library, including coverage of important techniques like traits and predicates. Also included are guidelines and considerations to remember when using standard containers and algorithms--topics rarely covered in-depth in other sources.
Readers will find solutions to such important questions as:
What pitfalls might you encounter when using std::map and std::set, and how can you safely avoid them?
What kinds of predicates are safe to use with the STL, what kinds aren't, and why?
What techniques are available for writing powerful generic template code that can change its own behavior based on the capabilities of the types it's given to work with?
When and how should you optimize your code? Why can (and do) fancy optimizations get us into trouble? And how can some of these answers change if you're writing multithread-safe code?
Does exception safety affect class design, or can it be retrofitted in as an afterthought?
How can you avoid the Siamese Twin problem when combining inheritance-based libraries from different vendors?
How can you safely use auto_ptr, and then use common design patterns to adapt it to avoid common pitfalls? Can you use auto_ptr as a class member? What must you know before you elect to use it that way?
Plus one of the most frequently recurring questions about modern C++: When and how should you use namespaces, anyway?
A must-have for the serious programmer, More Exceptional C++ provides a thorough and pragmatic understanding of the language while showing you how to write exceptional code in C++.
020170434XB11092001
Table of contents
- Copyright
- Foreword
- Preface
-
Generic Programming and the C++ Standard Library
- 1. Switching Streams
- 2. Predicates, Part 1: What remove() Removes
- 3. Predicates, Part 2: Matters of State
-
4. Extensible Templates: Via Inheritance or Traits?
-
Solution
- Requiring Member Functions
- Constraints Classes
- Requiring Inheritance, Take 1: IsDerivedFrom1 Value Helper
- Requiring Inheritance, Take 2: IsDerivedFrom2 Constraints Base Class
- Requiring Inheritance, Take 3: A Merged IsDerivedFrom
- Selecting Alternative Implementations
- Requirements versus Traits
- Inheritance versus Traits
-
Solution
- 5. Typename
- 6. Containers, Pointers, and Containers That Aren't
- 7. Using vector and deque
- 8. Using set and map
- 9. Equivalent Code?
- 10. Template Specialization and Overloading
- 11. Mastermind
- Optimization and Performance
-
Exception Safety Issues and Techniques
- 17. Constructor Failures, Part 1: Object Lifetimes
- 18. Constructor Failures, Part 2: Absorption?
- 19. Uncaught Exceptions
- 20. An Unmanaged Pointer Problem, Part 1: Parameter Evaluation
- 21. An Unmanaged Pointer Problem, Part 2: What About auto_ptr?
-
22. Exception-Safe Class Design, Part 1: Copy Assignment
-
Solution
- Review: Exception Safety Canonical Forms
- Analyzing the Cargill Widget Example
- A General Technique: Using the Pimpl Idiom
- A Potential Objection, and Why It's Unreasonable
- Conclusion 1: Exception Safety Affects a Class's Design
- Conclusion 2: You Can Always Make Your Code (Nearly) Strongly Exception-Safe
- Conclusion 3: Use Pointers Judiciously
-
Solution
- 23. Exception-Safe Class Design, Part 2: Inheritance
- Inheritance and Polymorphism
-
Memory and Resource Management
-
29. Using auto_ptr
-
Solution
- Problem: Arrays and auto_ptr Don't Mix
- Aside on a Non-problem: Zero-Length Arrays Are Okay
- Option 1: Roll Your Own auto_array
- Option 2: Use the Adapter Pattern (Score: 7 / 10)
- Option 3: Replace auto_ptr with Hand-Coded Exception-Handling Logic (Score: 1 / 10 )
- Option 4: Use a vector Instead of an Array (Score: 9.5 / 10 )
-
Solution
- 30. Smart Pointer Members, Part 1: A Problem with auto_ptr
- 31. Smart Pointer Members, Part 2: Toward a ValuePtr
-
29. Using auto_ptr
- Free Functions and Macros
-
Miscellaneous Topics
- 36. Initialization
- 37. Forward Declarations
- 38. Typedef
- 39. Namespaces, Part 1: Using-Declarations and Using-Directives
-
40. Namespaces, Part 2: Migrating to Namespaces
-
Solution
- Migrating to Namespaces, Safely and Effectively
-
Guidelines for a Good Long-Term Solution
- Namespace Rule #1: Never write using-directives in header files.
- Namespace Rule #2: Never write namespace using-declarations in header files.
- Namespace Rule #3: In implementation files, never write a using-declaration or a using-directive before an #include directive.
- “Kinda Sorta” Namespace Rule #4: Use C headers with the new style #include <cheader> instead of the old style #include <header.h>.
- Long-Term Approaches: A Motivating Example
- A Good Long-Term Solution
- A Not-So-Good Long-Term Solution
- An Effective Short-Term Solution
- Conclusion: Migrating to the Long-Term Solution
-
Solution
- Afterword
-
A. Optimizations That Aren't (in a Multithreaded World)
- Introduction
- What's the Fuss About?
- Recap: Plain Old Original:: String (Item 13)
- Using a Plain Old String: Single-Threaded
- Using a Plain Old String: Multithreaded
- Now Throw in an “Optimization”: Copy-On-Write (COW)
- Using a COW String: Multithreaded
- Mild versus Severe Inefficiencies
- Some Actual Numbers
- A Real-World Example: C++'s basic_string
- “Am I Affected?”
- Summary
- B. Test Results for Single-Threaded versus Multithread-Safe String Implementations
- Bibliography
Product information
- Title: More Exceptional C++
- Author(s):
- Release date: December 2001
- Publisher(s): Addison-Wesley Professional
- ISBN: None
You might also like
book
More Effective C++
More than 150,000 copies in print! Praise for Scott Meyers’ first book, Effective C++: “I heartily …
book
Hands-On Design Patterns with C++
A comprehensive guide with extensive coverage on concepts such as OOP, functional programming, generic programming, and …
book
C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond
Abrahams and Gurtovoy have written something close to a classic… marvelous fun to read… Read the …
book
C++ By Example: UnderC Learning Edition
C++ by Example includes 'UnderC,' an open-source language interpreter developed by the author, which shows the …