Leanpub Header

Skip to main content

Material for C++17 in Detail

Learn the Exciting Features of The New C++ Standard!

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
About

About

About the Book

Price

Pick Your Price...

Minimum price

$19.00

$29.00

You pay

$29.00

Author earns

$23.20
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 2)

2
The author will earn $24.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Bartłomiej Filipek

Bartłomiej (Bartek) Filipek is a C++ software developer from the beautiful city of Cracow in Poland He started his professional coding career in 2007. In 2010 he graduated from Jagiellonian University in Cracow, Poland, with a Master's Degree in Computer Science.

Bartek currently works at Xara, where he develops features for advanced document editors. He also has experience with desktop graphics applications, game development, large-scale systems for aviation, writing graphics drivers and even biofeedback. In the past, Bartek has also taught programming (mostly game and graphics programming courses) at local universities in Cracow.

Since 2011 Bartek has been regularly blogging at bfilipek.com and cppstories.com. Initially, the topics revolved around graphics programming, but now the blog focuses on core C++. He's also a co-organiser of the C++ User Group in Cracow. You can hear Bartek in one @CppCast episode where he talks about C++17, blogging and text processing.

Since October 2018, Bartek has been a C++ Expert for the Polish National Body, which works directly with ISO/IEC JTC 1/SC 22 (C++ Standardisation Committee).

In the same month, Bartek was awarded his first MVP title for the years 2019/2020 by Microsoft.

In his spare time, he loves assembling Lego models with his little son.

See his blog at cppstories.com.

Contents

Table of Contents

Part 1 - Language Features

1. Quick Start

  1. Working With Maps
  2. Debug Printing
  3. Let’s Start!

2. Removed or Fixed Language Features

  1. Removed Elements
  2. Removing the register Keyword
  3. Removing Deprecated operator++(bool)
  4. Removing Deprecated Exception Specifications
  5. Removing Trigraphs
  6. Exercise 1
  7. Fixes
  8. New auto rules for direct-list-initialisation
  9. static_assert With no Message
  10. Different begin and end Types in Range-Based For Loop
  11. Exercise 2
  12. Compiler Support
  13. Exercise 3
  14. Quiz 1

3. Language Clarification

  1. Stricter Expression Evaluation Order
  2. The Changes
  3. Exercise 4
  4. Guaranteed Copy Elision
  5. Updated Value Categories
  6. Exercise 5
  7. Dynamic Memory Allocation for Over-Aligned Data
  8. Exercise 6
  9. Exception Specifications in the Type System
  10. Exercise 7
  11. Compiler Support
  12. Exercise 8
  13. Quiz 2

4. General Language Features

  1. Structured Binding Declarations
  2. The Syntax
  3. Modifiers
  4. Structured Binding Limitations
  5. Binding
  6. Examples
  7. Expressive Code With Structured Bindings
  8. Providing Structured Binding Interface for Custom Class
  9. Exercise 9
  10. Init Statement for if and switch
  11. Exercise 10
  12. Inline Variables
  13. How Can it Simplify the Code?
  14. Exercise 11
  15. constexpr Lambda Expressions
  16. Exercise 12
  17. Capturing [*this] in Lambda Expressions
  18. Exercise 13
  19. Nested Namespaces
  20. Exercise 14
  21. __has_include Preprocessor Expression
  22. Exercise 15
  23. Compiler support
  24. Exercise 16
  25. Quiz 3

5. Templates

  1. Template Argument Deduction for Class Templates
  2. Deduction Guides
  3. CTAD Limitations
  4. Exercise 17
  5. Fold Expressions
  6. More Examples
  7. Exercise 18
  8. if constexpr
  9. Why Compile Time If?
  10. Template Code Simplification
  11. Examples
  12. Line Printer
  13. Declaring Custom get Functions
  14. Exercise 19
  15. Declaring Non-Type Template Parameters With auto
  16. Exercise 20
  17. Other Changes
  18. Allow typename in a Template Template Parameters.
  19. Allow Constant Evaluation for all Non-Type Template Arguments
  20. Variable Templates for Traits
  21. Pack Expansions in Using Declarations
  22. Logical Operation Metafunctions
  23. std::void_t Transformation Trait
  24. Compiler Support
  25. Exercise 21
  26. Quiz 4

6. Standard Attributes

  1. Why Do We Need Attributes?
  2. Exercise 22
  3. Before C++11
  4. GCC Specific Attributes
  5. MSVC Specific Attributes
  6. Clang Specific Attributes
  7. Exercise 23
  8. Attributes in C++11 and C++14
  9. In C++11 we have the following attributes:
  10. [[noreturn]] :
  11. [[carries_dependency]] :
  12. C++14 added:
  13. [[deprecated]] and [[deprecated("reason")]] :
  14. Exercise 24
  15. C++17 Additions
  16. [[fallthrough]] Attribute
  17. [[maybe_unused]] Attribute
  18. [[nodiscard]] Attribute
  19. Attributes for Namespaces and Enumerators
  20. Ignore Unknown Attributes
  21. Using Attribute Namespaces Without Repetition
  22. Exercise 25
  23. Section Summary
  24. Compiler support
  25. Exercise 26
  26. Quiz 5
  27. Part 2 - The Standard Library Changes

7. std::optional

  1. Introduction
  2. When to Use
  3. 1) If you want to represent a nullable type.
  4. 2) Return a result of some computation (processing) that fails to produce a value and is not an error.
  5. 3) To perform lazy-loading of resources.
  6. 4) To pass optional parameters into functions.
  7. A Basic Example
  8. Exercise 27
  9. std::optional Creation
  10. in_place Construction
  11. Default Construction
  12. Non Copyable/Movable Types
  13. Constructors With Many Arguments
  14. std::make_optional()
  15. Exercise 28
  16. Returning std::optional
  17. Be Careful With Braces when Returning
  18. Exercise 29
  19. Accessing The Stored Value
  20. Exercise 30
  21. std::optional Operations
  22. Changing the Value & Object Lifetime
  23. Comparisons
  24. Exercise 31
  25. Performance & Memory Consideration
  26. Exercise 32
  27. Migration from boost::optional
  28. Special case: optional and optional
  29. Exercise 33
  30. Examples of std::optional
  31. User Name with an Optional Nickname and Age
  32. Parsing ints From the Command Line
  33. Other Examples
  34. Exercise 34
  35. Summary
  36. Exercise 35
  37. Compiler Support
  38. Quiz 6

8. std::variant

  1. The Basics
  2. When to Use
  3. A Functional Background
  4. Exercise 36
  5. std::variant Creation
  6. About std::monostate
  7. In Place Construction
  8. Ambiguity
  9. Complex Types
  10. Unwanted Type Conversions And Narrowing
  11. Exercise 37
  12. Changing the Values
  13. Object Lifetime
  14. Exercise 38
  15. Accessing the Stored Value
  16. Exercise 39
  17. Visitors for std::variant
  18. Overload
  19. Visiting Multiple Variants
  20. Exercise 40
  21. Other std::variant Operations
  22. Exercise 41
  23. Exception Safety Guarantees
  24. Performance & Memory Considerations
  25. Exercise 42
  26. Migration From boost::variant
  27. Exercise 43
  28. Examples of std::variant
  29. Error Handling
  30. Parsing a Command Line
  31. Parsing a Config File
  32. State Machines
  33. Polymorphism
  34. Exercise 44
  35. Wrap Up
  36. Exercise 45
  37. Compiler Support
  38. Quiz 7

9. std::any

  1. The Basics
  2. When to Use
  3. Exercise 46
  4. std::any Creation
  5. In Place Construction
  6. Complex Types
  7. Exercise 47
  8. Changing the Value
  9. Object Lifetime
  10. Exercise 48
  11. Accessing The Stored Value
  12. Exercise 49
  13. Performance & Memory Considerations
  14. Exercise 50
  15. Migration from boost::any
  16. Exercise 51
  17. Examples of std::any
  18. Parsing files
  19. Message Passing
  20. Properties
  21. Exercise 52
  22. Wrap Up
  23. Exercise 53
  24. Compiler Support
  25. Quiz 8

10. std::string_view

  1. Exercise 54
  2. The Basics
  3. When to Use
  4. Exercise 55
  5. The std::basic_string_view Type
  6. Exercise 56
  7. std::string_view Creation
  8. Exercise 57
  9. Other Operations
  10. Exercise 58
  11. Risks Using string_view
  12. Taking Care of Not Null-Terminated Strings
  13. References and Temporary Objects
  14. Problems with the Initial Example
  15. Reference Lifetime Extension
  16. Exercise 59
  17. Initializing string Members from string_view
  18. Exercise 60
  19. Handling Non-Null Terminated Strings
  20. Printing with printf()
  21. Conversion Functions Like atoi()/atof():
  22. A General Solution
  23. Exercise 61
  24. Performance & Memory Considerations
  25. Strings in Constant Expressions
  26. Exercise 62
  27. Migration from boost::string_ref and boost::string_view
  28. Examples
  29. Working with Different String APIs
  30. String Split
  31. Exercise 63
  32. Wrap Up
  33. Compiler support:
  34. Exercise 64
  35. Quiz 9

11. String Conversions

  1. Elementary String Conversions
  2. Exercise 65
  3. Converting From Characters to Numbers: from_chars
  4. Examples
  5. 1) Integral types
  6. 2) Floating Point
  7. Parsing a Command Line
  8. Exercise 66
  9. Converting Numbers into Characters: to_chars
  10. An Example
  11. Exercise 67
  12. The Benchmark
  13. Exercise 68
  14. Summary
  15. Compiler support
  16. Exercise 69
  17. Quiz 10

12. Searchers & String Matching

  1. Overview of String Matching Algorithms
  2. Exercise 70
  3. New Algorithms Available in C++17
  4. Using Searchers
  5. Exercise 71
  6. Examples
  7. Performance Experiments
  8. DNA Matching
  9. Exercise 72
  10. Summary
  11. Exercise 73
  12. Compiler support
  13. Quiz 11

13. Filesystem

  1. Filesystem Overview
  2. Core Parts of The Library
  3. Demo
  4. Exercise 74
  5. The Path Object
  6. Path Operations
  7. Comparison
  8. Path Composition
  9. Stream Operators
  10. Path Formats and Conversion
  11. Exercise 75
  12. The Directory Entry & Directory Iteration
  13. Traversing a Path with Directory Iterators
  14. directory_entry Methods
  15. Exercise 76
  16. Supporting Functions
  17. Getting & Displaying the File Time
  18. File Permissions
  19. Setting Permissions
  20. Note for Windows
  21. Exercise 77
  22. Error Handling & File Races
  23. File Races
  24. Examples
  25. Loading a File into a String
  26. Creating Directories
  27. Filtering Files Using Regex
  28. Optimisation & Code Cleanup
  29. Exercise 78
  30. Lesson Summary
  31. Compiler Support
  32. GCC/libstdc++
  33. Clang/libc++
  34. Visual Studio
  35. Compiler Support Summary
  36. Exercise 79
  37. Quiz 12

14. Parallel STL Algorithms

  1. Introduction
  2. Not Only Threads
  3. Overview
  4. Exercise 80
  5. Execution Policies
  6. Understanding Execution Policies
  7. Limitations and Unsafe Instructions
  8. Exceptions
  9. Exercise 81
  10. Algorithm Update
  11. New Algorithms
  12. For Each Algorithm
  13. Understanding Reduce Algorithms
  14. transform_reduce - Fused Algorithm
  15. Scan Algorithms
  16. Exercise 82
  17. Performance of Parallel Algorithms
  18. Exercise 83
  19. Examples
  20. Benchmark
  21. Processing Several Containers At the Same Time
  22. Separate Container of Indices
  23. Zip Iterators
  24. Erroneous Technique
  25. Counting Elements
  26. More Examples
  27. Exercise 84
  28. Lesson Summary
  29. Exercise 85
  30. Compiler Support
  31. Exercise 86
  32. Quiz 13

15. Other Changes In The Library

  1. std::byte
  2. Exercise 87
  3. Improvements for Maps and Sets
  4. Splicing
  5. Emplace Enhancements for Maps and Unordered Maps
  6. try_emplace Method
  7. insert_or_assign Method
  8. Exercise 88
  9. Return Type of Emplace Methods
  10. Exercise 89
  11. Sampling Algorithms
  12. Exercise 90
  13. New Mathematical Functions
  14. Exercise 91
  15. Shared Pointers and Arrays
  16. Non-member size(), data() and empty()
  17. Exercise 92
  18. constexpr Additions to the Standard Library
  19. Exercise 93
  20. std::scoped_lock
  21. Polymorphic Allocator, pmr
  22. Core elements of pmr:
  23. More Information
  24. Exercise 94
  25. Compiler support
  26. Quiz 14

16. Removed And Deprecated Library Features

  1. Removing auto_ptr
  2. Exercise 95
  3. Removed std::random_shuffle
  4. Exercise 96
  5. “Removing Old functional Stuff”
  6. Exercise 97
  7. std::iterator Is Deprecated
  8. Exercise 98
  9. Other Smaller Removed or Deprecated Items
  10. Deprecating shared_ptr::unique()
  11. Deprecating
  12. Removing Deprecated Iostreams Aliases
  13. Deprecate C library headers
  14. Deprecate std::result_of
  15. Deprecate std::memory_order_consume Temporarily
  16. Remove allocator support from std::function
  17. Exercise 99
  18. Compiler support
  19. Exercise 100
  20. Quiz 15
  21. Part 3 - More Examples and Use Cases

17. Refactoring with std::optional and std::variant

  1. The Use Case
  2. Exercise 101
  3. The Tuple Version
  4. Exercise 102
  5. A Separate Structure
  6. Exercise 103
  7. With std::optional
  8. With std::variant
  9. Exercise 104
  10. Wrap up
  11. Exercise 105
  12. Quiz 16

18. Enforcing Code Contracts With [[nodiscard]]

  1. Introduction
  2. Exercise 106
  3. Where Can It Be Used?
  4. Errors
  5. Factories / Handles
  6. When Returning Non-Trivial Types?
  7. Code With No Side Effects?
  8. Everywhere?!
  9. Exercise 107
  10. How to Ignore [[nodiscard]]
  11. Exercise 108
  12. Before C++17
  13. Exercise 109
  14. Summary
  15. Quiz 17

19. Replacing enable_if with if constexpr - Factory with Variable Arguments

  1. The Problem
  2. Exercise 110
  3. Before C++17
  4. Exercise 111
  5. With if constexpr
  6. Exercise 112
  7. Summary
  8. Quiz 18

20. How to Parallelise CSV Reader

  1. Introduction and Requirements
  2. Exercise 113
  3. The Serial Version
  4. The Main
  5. Converting Lines into Records
  6. The OrderRecord Class
  7. The conversion
  8. Calculations
  9. Design Enhancements
  10. Running the Code
  11. Exercise 114
  12. Using Parallel Algorithms
  13. Data Size & Instruction Count Matters
  14. Parallel Data Conversion
  15. Parallel Calculations
  16. Exercise 115
  17. Tests
  18. Mid Size Files 1k Lines 10 Files
  19. Large Set 10k Lines in 10 Files
  20. Largest Set 100k Lines in 10 Files
  21. Exercise 116
  22. Wrap up & Discussion
  23. Additional Modifications and Options
  24. Exercise 117
  25. Quiz 19

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.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

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. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub