Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Design Patterns with C++

You're reading from   Hands-On Design Patterns with C++ Solve common C++ problems with modern design patterns and build robust applications

Arrow left icon
Product type Paperback
Published in Jul 2023
Publisher Packt
ISBN-13 9781804611555
Length 626 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Fedor G. Pikus Fedor G. Pikus
Author Profile Icon Fedor G. Pikus
Fedor G. Pikus
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Part 1: Getting Started with C++ Features and Concepts
2. Chapter 1: An Introduction to Inheritance and Polymorphism FREE CHAPTER 3. Chapter 2: Class and Function Templates 4. Chapter 3: Memory and Ownership 5. Part 2: Common C++ Idioms
6. Chapter 4: Swap – from Simple to Subtle 7. Chapter 5: A Comprehensive Look at RAII 8. Chapter 6: Understanding Type Erasure 9. Chapter 7: SFINAE, Concepts, and Overload Resolution Management 10. Part 3: C++ Design Patterns
11. Chapter 8: The Curiously Recurring Template Pattern 12. Chapter 9: Named Arguments, Method Chaining, and the Builder Pattern 13. Chapter 10: Local Buffer Optimization 14. Chapter 11: ScopeGuard 15. Chapter 12: Friend Factory 16. Chapter 13: Virtual Constructors and Factories 17. Chapter 14: The Template Method Pattern and the Non-Virtual Idiom 18. Part 4: Advanced C++ Design Patterns
19. Chapter 15: Policy-Based Design 20. Chapter 16: Adapters and Decorators 21. Chapter 17: The Visitor Pattern and Multiple Dispatch 22. Chapter 18: Patterns for Concurrency 23. Assessments 24. Index 25. Other Books You May Enjoy

ScopeGuard

This chapter covers a pattern that can be seen as a generalization of the RAII idiom we studied earlier. In its earliest form, it is an old and established C++ pattern, however, it is also one that has particularly benefited from the language additions in C++11, C++14, and C++17. We will witness the evolution of this pattern as the language becomes more powerful. The ScopeGuard pattern exists at the intersection of declarative programming (say what you want to happen, not how you want it done) and error-safe programs (especially exception safety). We will have to learn a bit about both before we fully understand ScopeGuard.

The following topics will be covered in this chapter:

  • How can we write error-safe and exception-safe code? How does RAII make error handling easier?
  • What is composability as applied to error handling?
  • Why is RAII not powerful enough for error handling, and how is it generalized? How can we implement declarative error handling in C+...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime