C++17 in Detail
C++17 in Detail
Learn the Exciting Features of The New C++ Standard!
About the Book
If you’ve ever asked “what’s in C++17 and what does it mean for me and my code?” — and I hope you have — then this book is for you.
Herb Sutter, herbsutter.com
Available also as the paperback version @Amazon and the interactive online course @Educative
C++11 was a major update for the language. With all the modern features like lambdas, constexpr, variadic templates, threading, range-based for loops, smart pointers and many more powerful elements, it was enormous progress for the language. Even now, in 2018, lots of teams struggle to modernise their projects to leverage all the modern features. Later there was a minor update - C++14, which improved some things from the previous standard and added a few smaller elements. With C++17 we got a lot of mixed emotions.
Although C++17 is not as big as C++11, it's larger than C++14. Everyone expected modules, co-routines, concepts and other powerful features, but it wasn't possible to prepare everything on time.
Is C++17 weak?
Far from it! And this book will show you why!
I spent hundreds of hours investigating how the new things work in order to make a nice and practical book for you. The book will not only save your time but also will guide you through all the nuances of the language.
The book brings you exclusive content about C++17 and draws from the experience of many articles that have appeared on bfilipek.com (and cppstories.com). The chapters were rewritten from the ground-up and updated with the latest information. All of that equipped with lots of new examples and practical tips. Additionally, the book provides insight into the current implementation status, compiler support, performance issues and other relevant knowledge to boost your current projects.
If you have experience with C++11/14 and you want to move forward into the latest C++ standard, then this book is for you.
Here are the features you'll learn:
Part One: C++17 Language features
- Fixes and deprecation
- Language clarification
- General language features
- Templates
- Attributes
Part Two: C++17 The Standard Library
- std::optional
- std::variant
- std::any
- std::string_view
- String Conversions
- String Matching & Searchers
- Filesystem
- Parallel STL
- Other Changes
Part Three: More Examples and Use Cases
- Refactoring with std::optional
- Using if constexpr
- Using [[nodiscard]] attribute
- How to parallelise applications
Book Mentions:
"C++17 In Detail" appeared in the Visual C++ Team Blog as suggested books for learning C++17!
Have a look: Books on C++17
Review @CppDepend Blog https://cppdepend.com/blog/?p=1180
Review @A Sawicki Blog: http://asawicki.info/news_1715_book_review_c17_in_detail.html
There's also a book page at Goodreads: C++17 In Detail @Goodreads
Other formats:
- The book is also available in print at Amazon: C++17 in Detail Paperback
- And also as an interactive course at Educative: C++17 in Detail: A Deep Dive
Technical details:
I optimized this book for a PDF reading experience, but other ebook formats should also look good. If you have any issues with the copies, let me know and I'll try to update the formatting.
Packages
The Book
Includes:
Code Samples
C++ Code Samples for the book
PDF
EPUB
WEB
English
Team Edition, 5 Copies (with 50% discount)
Ideal for your team or a company library!
Includes:
Code Samples
C++ Code Samples for the book
PDF
EPUB
WEB
English
Bundles that include this book
About the Contributors

Primary Technical Reviewer
Jacek Galowicz is a Software Engineer with roughly a decade of professional experience in C++. He got his master of science degree in electrical engineering at RWTH Aachen University in Germany.
Jacek co-founded the Cyberus Technology GmbH in early 2017 and works on products around low-level cybersecurity, virtualization, microkernels, and advanced testing infrastructure. At former jobs, he implemented performance- and security-sensitive microkernel operating systems for Intel x86 virtualization at Intel and FireEye in Germany. In general, he gained experience with kernel driver development, 3D graphics programming, databases, network communication, physics simulation, mostly in C or C++.
In his free time, Jacek maintains a little C++ blog, which has seen some lack of love while he wrote the C++17 STL Cookbook. He is a regular visitor of the C++ Usergroups in Hannover and Braunschweig. In order to do meta programming and generic programming better, he also learned and uses Haskell, which in turn sparked his interest to generally bring the advantages of purely functional programming to C++.
Reader Testimonials

Jonathan Boccara (fluentcpp.com)
C++17 in Detail is the ideal guide for C++ programmers who want to leverage on C++17 to write better code. The book shows the new features of the language under a practical angle, with copious details and code examples while still being accessible and easy to read. Bartlomiej Filipek's work is my go-to reference for C++17 features, and C++17 in Detail captures it all in one book.

Arne Mertz (arne-mertz.de)
With a new C++ standard delivering more features to an already complex language every 3 years, it is hard to keep track and easy to get lost. With his articles and this book, Bartek provides the much needed comprehensive view on not only what has changed, but also why it has changed and how we can use it to make our code more expressive. There's nothing left to wish for except that he can keep up with the committee and deliver a C++20 version in three years ;-)
Victor Ciura ( @ciura_victor )
C++17 in Detail is a whirlwind tour of the new and exciting features of the new C++17 ISO standard. Incubated from Bartek's excellent series of articles, his book properly organizes the topics and really goes into details when needed. Whether you're coming to modern C++ just now or you are a seasoned C++ developer and want to learn all the nitty-gritty of the new standard features, you'll find in this book amazing examples (minimalistic, yet practical) and explanations to help you along the way.
Karol Gasiński (@karolgasinski)
It's a very comprehensive guide into the C++17 standard. Detailed but allows easy navigation between described features. Definitely, a good place to start for anybody who wants to catch up with latest C++.
Marco Arena (marcoarena.com)
Bartlomiej Filipek has shaped C++17 in Detail by turning his strong blogging experience into a fundamental book for C++ developers who want to quickly get up and running with C++17 features with a practical approach. The book has a lively style, it clearly integrates feedback and pearls that Bartlomiej has gathered in the last years and it consists in an effective balance among theoretical concepts, references to the standard and official papers, and real examples.
Table of Contents
-
- About the Author
-
Technical Reviewer
- Additional Reviewers & Supporters
- Revision History
- Foreword
- Preface
-
About the Book
- Who This Book is For
- Overall Structure of the Book
- Reader Feedback
- Example Code
-
Part 1 - Language Features
- 1. Quick Start
-
2. Removed or Fixed Language Features
- Removed Elements
- Fixes
- Compiler Support
-
3. Language Clarification
- Stricter Expression Evaluation Order
- Guaranteed Copy Elision
- Dynamic Memory Allocation for Over-Aligned Data
- Exception Specifications in the Type System
- Compiler Support
-
4. General Language Features
- Structured Binding Declarations
-
Init Statement for
if
andswitch
- Inline Variables
-
constexpr
Lambda Expressions -
Capturing
[*this]
in Lambda Expressions - Nested Namespaces
-
__has_include
Preprocessor Expression - Compiler support
-
5. Templates
- Template Argument Deduction for Class Templates
- Fold Expressions
-
if constexpr
-
Declaring Non-Type Template Parameters With
auto
- Other Changes
- Compiler Support
-
6. Standard Attributes
- Why Do We Need Attributes?
- Before C++11
- Attributes in C++11 and C++14
- C++17 Additions
- Section Summary
- Compiler support
-
Part 2 - The Standard Library Changes
-
7.
std::optional
- Introduction
-
std::optional
Creation -
Returning
std::optional
- Accessing The Stored Value
-
std::optional
Operations - Performance & Memory Consideration
-
Migration from
boost::optional
-
Special case:
optional<bool>
andoptional<T*>
-
Examples of
std::optional
- Summary
- Compiler Support
-
8.
std::variant
- The Basics
-
std::variant
Creation - Changing the Values
- Accessing the Stored Value
-
Visitors for
std::variant
-
Other
std::variant
Operations - Exception Safety Guarantees
- Performance & Memory Considerations
-
Migration From
boost::variant
-
Examples of
std::variant
- Wrap Up
- Compiler Support
-
9.
std::any
- The Basics
-
std::any
Creation - Changing the Value
- Accessing The Stored Value
- Performance & Memory Considerations
-
Migration from
boost::any
-
Examples of
std::any
- Wrap Up
- Compiler Support
-
10.
std::string_view
- The Basics
-
The
std::basic_string_view
Type -
std::string_view
Creation - Other Operations
-
Risks Using
string_view
-
Initializing
string
Members fromstring_view
- Handling Non-Null Terminated Strings
- Performance & Memory Considerations
-
Migration from
boost::string_ref
andboost::string_view
- Examples
- Wrap Up
-
11. String Conversions
- Elementary String Conversions
-
Converting From Characters to Numbers:
from_chars
-
Converting Numbers into Characters:
to_chars
- The Benchmark
- Summary
- Compiler support
-
12. Searchers & String Matching
- Overview of String Matching Algorithms
- New Algorithms Available in C++17
- Examples
- Summary
- Compiler support
-
13. Filesystem
- Filesystem Overview
- Demo
- The Path Object
- The Directory Entry & Directory Iteration
- Supporting Functions
- Error Handling & File Races
- Examples
- Chapter Summary
- Compiler Support
-
14. Parallel STL Algorithms
- Introduction
- Overview
- Execution Policies
- Algorithm Update
- New Algorithms
- Performance of Parallel Algorithms
- Examples
- Chapter Summary
- Compiler Support
-
15. Other Changes In The Library
-
std::byte
- Improvements for Maps and Sets
- Return Type of Emplace Methods
- Sampling Algorithms
- New Mathematical Functions
- Shared Pointers and Arrays
-
Non-member
size()
,data()
andempty()
-
constexpr
Additions to the Standard Library -
std::scoped_lock
-
Polymorphic Allocator,
pmr
- Compiler support
-
-
16. Removed And Deprecated Library Features
-
Removing
auto_ptr
-
Removed
std::random_shuffle
- “Removing Old functional Stuff”
-
std::iterator
Is Deprecated - Other Smaller Removed or Deprecated Items
- Compiler support
-
Removing
-
7.
-
Part 3 - More Examples and Use Cases
-
17. Refactoring with
std::optional
andstd::variant
- The Use Case
- The Tuple Version
- A Separate Structure
-
With
std::optional
-
With
std::variant
- Wrap up
-
18. Enforcing Code Contracts With
[[nodiscard]]
- Introduction
- Where Can It Be Used?
-
How to Ignore
[[nodiscard]]
- Before C++17
- Summary
-
19. Replacing
enable_if
withif constexpr
- Factory with Variable Arguments- The Problem
- Before C++17
-
With
if constexpr
- Summary
-
20. How to Parallelise CSV Reader
- Introduction and Requirements
- The Serial Version
- Using Parallel Algorithms
- Tests
- Wrap up & Discussion
-
Appendix A - Compiler Support
- GCC
- Clang
- VisualStudio - MSVC
- Compiler Support of C++17 Features
- Appendix B - Resources and References
- Index
-
17. Refactoring with
- Notes
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,046,757writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
Talking with Tech Leads
Patrick KuaA book for Tech Leads, from Tech Leads. Discover how more than 35 Tech Leads find the delicate balance between the technical and non-technical worlds. Discover the challenges a Tech Lead faces and how to overcome them. You may be surprised by the lessons they have to share.Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Functional Event-Driven Architecture
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
Take your functional programming skills to the next level by joining me in developing a distributed system powered by Apache Pulsar and Fs2 streams, all in Scala 3!
The Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #6
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #8
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...