C++17 - The Complete Guide
C++17 - The Complete Guide (C++17 - The Complete Guide)
$8.90
Minimum price
$37.90
Suggested price
C++17 - The Complete Guide

This book is 85% complete

Last updated on 2018-10-15

About the Book

C++17 is the next evolution in modern C++ programming, which is already at least partially supported by the latest version of gcc, clang, and Visual C++. Although it is not as big a step as C++11, it contains a large number of small and valuable language and library features, which will change the way we program in C++. As usual, not everything is self-explanatory, combining new features gives even more power, and there are hidden traps.

This book presents all the new language and library features in C++17. It covers the motivation and context of each new feature with examples and background information. The focus is on how these features impact day-to-day programming, what it means to combine them, and how to benefit from this in practice.

Buy early, pay less, free updates.

Note that this book will be published step-by-step.

Currently, the first 270 pages are published, covering the most important C++17 features. The first version was available since December 15, 2017, after I integrated all feedback, examples, and caveats about the features, I want to describe in the first version (I especially had to integrate things I learned recently at the major C++ conference CppCon).

The current version already covers the following topics, including how they play together in practice:

  • Structured bindings, if/switch with initializers, inline variables, aggregate extensions, copy elision and materialization, lambda extensions,
  • nested namespaces, defined expression evaluation order, relaxed enum initialization, relaxed static_assert, #__has_include
  • class template argument deduction, compile-time if, fold expressions, strings and auto as template parameters, extended using, overloading lambdas
  • optional<>, variant<>, any, byte, string_view, and some examples from the file system library
  • type trait suffix _v, new type traits, and some library fixes
  • new/delete for over-aligned data

Much more will come in the following versions (see www.cppstd17.com for a details).

As written, once you bought it you will get all updates for free.

PDF versus Other Formats

I wrote the book in LaTeX and generated PDF myself directly (the way I did with all my other books). The other formats (epub, mobi, and online reading) come from the leanpub markdown interface, for which I generate the necessary input from LaTeX by script.

Thus, the PDF layout has a better quality than the other formats. For example, the syntax highlighting rules for the formats other than PDF have to get fixed as soon as possible and the index is missing yet. Leanpub and me are working on corresponding improvements.

I hope you anyway enjoy and benefit.

Nico

#cpp17tcg

Table of Contents

  •  
    • 1. Preface
      • 1.1 Versions of This Book
      • 1.2 Acknowledgments
    • 2. About This Book
      • 2.1 What You Should Know Before Reading This Book
      • 2.2 Overall Structure of the Book
      • 2.3 How to Read This Book
      • 2.4 The C++17 Standard
      • 2.5 Example Code and Additional Information
      • 2.6 Feedback
  • I Basic Language Features
    • 3. Structured Bindings
      • 3.1 Structured Bindings in Detail
      • 3.2 Where Structured Bindings can be Used
        • 3.2.1 Structures and Classes
        • 3.2.2 Raw Arrays
        • 3.2.3 std::pair, std::tuple, and std::array
      • 3.3 Providing a Tuple-Like API for Structured Bindings
      • 3.4 Afternotes
    • 4. if and switch with Initialization
      • 4.1 if with Initialization
      • 4.2 switch with Initialization
      • 4.3 Afternotes
    • 5. Inline Variables
      • 5.1 Motivation of Inline Variables
      • 5.2 Using Inline Variables
      • 5.3 constexpr now implies inline
      • 5.4 Inline Variables and thread_local
      • 5.5 Afternotes
    • 6. Aggregate Extensions
      • 6.1 Motivation for Extended Aggregate Initialization
      • 6.2 Using Extended Aggregate Initialization
      • 6.3 Definition of Aggregates
      • 6.4 Backward Incompatibilities
      • 6.5 Afternotes
    • 7. Mandatory Copy Elision or Passing Unmaterialized Objects
      • 7.1 Motivation for Mandatory Copy Elision for Temporaries
      • 7.2 Benefit of Mandatory Copy Elision for Temporaries
      • 7.3 Clarified Value Categories
        • 7.3.1 Value Categories
        • 7.3.2 Value Categories Since C++17
      • 7.4 Unmaterialized Return Value Passing
      • 7.5 Afternotes
    • 8. Lambda Extensions
      • 8.1 constexpr Lambdas
      • 8.2 Passing Copies of this to Lambdas
      • 8.3 Capturing by Reference
      • 8.4 Afternotes
    • 9. New Attributes and Attribute Features
      • 9.1 Attribute [[nodiscard]]
      • 9.2 Attribute [[maybe_unused]]
      • 9.3 Attribute [[fallthrough]]
      • 9.4 General Attribute Extensions
      • 9.5 Afternotes
    • 10. Other Language Features
      • 10.1 Nested Namespaces
      • 10.2 Defined Expression Evaluation Order
      • 10.3 Relaxed Enum Initialization from Integral Values
      • 10.4 Fixed Direct List Initialization with auto
      • 10.5 Hexadecimal Floating-Point Literals
      • 10.6 UTF-8 Character Literals
      • 10.7 Exception Specifications as Part of the Type
      • 10.8 Single-Argument static_assert
      • 10.9 Preprocessor Condition __has_include
      • 10.10 Afternotes
  • II Template Features
    • 11. Class Template Argument Deduction
      • 11.1 Usage of Class Template Argument Deduction
        • 11.1.1 Copying by Default
        • 11.1.2 Deducing the Type of Lambdas
        • 11.1.3 No Partial Class Template Argument Deduction
        • 11.1.4 Class Template Argument Deduction Instead of Convenience Functions
      • 11.2 Deduction Guides
        • 11.2.1 Using Deduction Guides to Force Decay
        • 11.2.2 Non-Template Deduction Guides
        • 11.2.3 Deduction Guides versus Constructors
        • 11.2.4 Explicit Deduction Guides
        • 11.2.5 Deduction Guides for Aggregates
        • 11.2.6 Standard Deduction Guides
      • 11.3 Afternotes
    • 12. Compile-Time if
      • 12.1 Motivation for Compile-Time if
      • 12.2 Using Compile-Time if
        • 12.2.1 Caveats for Compile-Time if
        • 12.2.2 Other Compile-Time if Examples
      • 12.3 Compile-Time if with Initialization
      • 12.4 Using Compile-Time if Outside Templates
      • 12.5 Afternotes
    • 13. Fold Expressions
      • 13.1 Motivation for Fold Expressions
      • 13.2 Using Fold Expressions
        • 13.2.1 Dealing with Empty Parameter Packs
        • 13.2.2 Supported Operators
        • 13.2.3 Using Fold Expressions for Types
      • 13.3 Afternotes
    • 14. Dealing with Strings as Template Parameters
      • 14.1 Using Strings in Templates
      • 14.2 Afternotes
    • 15. Placeholder Types like auto as Template Parameters
      • 15.1 Using auto as Template Parameter
        • 15.1.1 Parameterizing Templates for Characters and Strings
        • 15.1.2 Defining Metaprogramming Constants
      • 15.2 Using auto as Variable Template Parameter
      • 15.3 Using decltype(auto) as Template Parameter
      • 15.4 Afternotes
    • 16. Extended Using Declarations
      • 16.1 Using Variadic Using Declarations
      • 16.2 Variadic Using Declarations for Inheriting Constructors
      • 16.3 Afternotes
  • III New Library Components
    • 17. std::optional<>
      • 17.1 Using std::optional<>
        • 17.1.1 Optional Return Values
        • 17.1.2 Optional Arguments and Data Members
      • 17.2 std::optional<> Types and Operations
        • 17.2.1 std::optional<> Types
        • 17.2.2 std::optional<> Operations
      • 17.3 Special Cases
        • 17.3.1 Optional of Boolean or Raw Pointer Values
        • 17.3.2 Optional of Optional
      • 17.4 Afternotes
    • 18. std::variant<>
      • 18.1 Using std::variant<>
      • 18.2 std::variant<> Types and Operations
        • 18.2.1 std::variant<> Types
        • 18.2.2 std::variant<> Operations
        • 18.2.3 Visitors
        • 18.2.4 Valueless by Exception
      • 18.3 Special Cases
        • 18.3.1 Having Both bool and std::string Alternatives
      • 18.4 Afternotes
    • 19. std::any
      • 19.1 Using std::any
      • 19.2 std::any Types and Operations
        • 19.2.1 Any Types
        • 19.2.2 Any Operations
      • 19.3 Afternotes
    • 20. std::byte
      • 20.1 Using std::byte
      • 20.2 std::byte Types and Operations
        • 20.2.1 std::byte Types
        • 20.2.2 std::byte Operations
      • 20.3 Afternotes
    • 21. String Views
      • 21.1 Differences to std::string
      • 21.2 Using String Views
      • 21.3 Using String Views Similar to Strings
        • 21.3.1 String View Considered Harmful
      • 21.4 String View Types and Operations
        • 21.4.1 Concrete String View Types
        • 21.4.2 String View Operations
        • 21.4.3 String View Support by Other Types
      • 21.5 Using String Views in API’s
        • 21.5.1 Using String Views to Initialize Strings
        • 21.5.2 Using String Views instead of Strings
      • 21.6 Afternotes
    • 22. The Filesystem Library
      • 22.1 Basic Examples
        • 22.1.1 Print Attributes of a Passed Filesystem Path
        • 22.1.2 Switch Over Filesystem Types
        • 22.1.3 Create Different Types of Files {#createfiles.cpp}
        • 22.1.4 Dealing with Filesystems Using Parallel Algorithms
      • 22.2 Principles and Terminology
        • 22.2.1 General Portability Disclaimer
        • 22.2.2 Namespace
        • 22.2.3 Paths
        • 22.2.4 Normalization
        • 22.2.5 Member versus Free-Standing Functions
        • 22.2.6 Error Handling
        • 22.2.7 File Types
      • 22.3 Path Operations
        • 22.3.1 Path Creation
        • 22.3.2 Path Inspection
        • 22.3.3 Path I/O and Conversions
        • 22.3.4 Conversions Between Native and Generic Format
        • 22.3.5 Path Modifications
        • 22.3.6 Path Comparisons
        • 22.3.7 Other Path Operations
      • 22.4 Filesystem Operations
        • 22.4.1 File Attributes
        • 22.4.2 File Status
        • 22.4.3 Permissions
        • 22.4.4 Filesystem Modifications
        • 22.4.5 Symbolic Links and Filesystem-Dependent Path Conversions
        • 22.4.6 Other Filesystem Operations
      • 22.5 Iterating Over Directories
        • 22.5.1 Directory Entries
      • 22.6 Afternotes
  • IV Library Extensions and Modifications
    • 23. Type Traits Extensions
      • 23.1 Type Traits Suffix _v
      • 23.2 New Type Traits
      • 23.3 std::bool_constant<>
      • 23.4 std::void_t<>
      • 23.5 Afternotes
    • 24. Parallel STL Algorithms
      • 24.1 Using Parallel Algorithms
        • 24.1.1 A Standard Algorithms in Parallel
        • 24.1.2 Using New Algorithms
      • 24.2 Parallel Algorithms in Detail
      • 24.3 Afternotes
    • 25. Container Extensions
      • 25.1 Container-Support of Incomplete Types
      • 25.2 Node Handles
      • 25.3 Afternotes
    • 26. Multi-Threading and Concurrency
      • 26.1 Supplementary Mutexes and Locks
        • 26.1.1 std::scoped_lock
        • 26.1.2 std::shared_mutex
      • 26.2 is_always_lock_free() for Atomics
      • 26.3 Cache-Line Sizes
      • 26.4 Afternotes
    • 27. Other Small Library Features and Modifications
      • 27.1 as_const()
        • 27.1.1 Capturing by Const Reference
      • 27.2 Afternotes
  • V Expert Utilities
    • 28. Polymorphic Memory Resources (PMR)
      • 28.1 Using Standard Memory Resources
        • 28.1.1 Motivating Example
        • 28.1.2 Standard Memory Resources
        • 28.1.3 Standard Memory Resources in Detail
      • 28.2 Defining Own Memory Resources
        • 28.2.1 Equality of Memory Resources
      • 28.3 Providing Memory Resources Support for Own Types
        • 28.3.1 Definition of a PMR Type
        • 28.3.2 Usage of a PMR Type
        • 28.3.3 Dealing with the Different Types
      • 28.4 Afternotes
    • 29. new and delete with Over-Aligned Data
      • 29.1 Using new with Alignments
        • 29.1.1 Distinct Dynamic/Heap Memory Arenas
        • 29.1.2 Passing the Alignment with the new Expression
      • 29.2 Implementing operator new() for Aligned Memory
        • 29.2.1 Implementing Aligned Allocation Before C++17
        • 29.2.2 Implementing Type-Specific operator new()
      • 29.3 Implementing Global operator new()
        • 29.3.1 Backward Incompatibilities
      • 29.4 Tracking all ::new Calls
      • 29.5 Afternotes
    • 30. Other Library Improvements for Experts
      • 30.1 Low-Level Conversions between Character Sequences and Numeric Values
        • 30.1.1 Example Usage
      • 30.2 Afternotes
    • Glossary
      • B
        • bitmask type
      • F
        • full specialization
      • I
        • incomplete type
      • P
        • partial specialization
      • S
        • small/short string optimization (SSO)
      • V
        • variable template
        • variadic template
    • Index
  • Notes

About the Author

Nicolai Josuttis
Nicolai Josuttis

Nicolai Josuttis (http://www.josuttis.com) is an independent system architect, technical manager, author, consultant, and trainer being active in C++ standardization for 20 years. He designs mid-sized and large software systems for the telecommunications, traffic, finance, and manufacturing industries.

He is well known in the programming community because he not only speaks and writes with authority, being the (co-)author of the world-wide best sellers The C++ Standard Library, C++ Templates, and SOA in Practice, but is also an innovative presenter, having talked at various conferences and events.

The Leanpub 45-day 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Write and Publish on Leanpub

Authors and publishers use Leanpub to publish amazing in-progress and completed ebooks, just like this one. You can use Leanpub to write, publish and sell your book as well! Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks. Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. It really is that easy.

Learn more about writing on Leanpub