listings-Chap23-README.md
Listings of Chap23.docx
This is linked summary of the listings. You can also view it on one page.
- Listing 23.1: The call to a function template works so long as the function body is valid with the template parameters.
- Book: lst-0010-book.cpp
- Godbolt: lst-0010-godb.cpp, https://godbolt.org/z/aMPj3K7EE
- Listing 23.2: With and without explicit type specification during the call.
- Book: lst-0013-book.cpp
- Godbolt: lst-0013-godb.cpp, https://godbolt.org/z/816Ys17aT
- Listing 23.3: A template parameter can also be a constant number.
- Book: lst-0015-book.cpp
- Godbolt: lst-0015-godb.cpp, https://godbolt.org/z/c9xzM7EhP
- Listing 23.4: With auto as a template parameter, you can specify any simple value.
- Book: lst-0017-book.cpp
- Listing 23.5: With “auto” and …, you can specify any values as template parameters.
- Book: lst-0018-book.cpp
- Listing 23.6: For “TYPE”, the compiler determines “const&”.
- Book: lst-0020-book.cpp
- Godbolt: lst-0020-godb.cpp, https://godbolt.org/z/fev879zaK
- Listing 23.7: A method can also be a template.
- Book: lst-0022-book.cpp
- Godbolt: lst-0022-godb.cpp, https://godbolt.org/z/bfofn76Ke
- Listing 23.8: You will also find various function templates in the standard library.
- Book: lst-0023-book.cpp
- Godbolt: lst-0023-godb.cpp, https://godbolt.org/z/oTn1K4sGG
- Listing 23.9: Pass your own algorithm ranges as arguments, not the container.
- Book: lst-0024-book.cpp
- Godbolt: lst-0024-godb.cpp, https://godbolt.org/z/h3baE65od
- Listing 23.10: Pass your own algorithm iterators as arguments, not the container.
- Book: lst-0025-book.cpp
- Godbolt: lst-0025-godb.cpp, https://godbolt.org/z/13eMxKTfj
- Listing 23.11: How to find the range of integer types.
- Book: lst-0027-book.cpp
- Godbolt: lst-0027-godb.cpp, https://godbolt.org/z/r83Yeon7r
- Listing 23.12: A function as a parameter.
- Book: lst-0028-book.cpp
- Listing 23.13: Use the name of a suitable function as a function parameter.
- Book: lst-0031-book.cpp
- Godbolt: lst-0031-godb.cpp, https://godbolt.org/z/q719j41er
- Listing 23.14: It doesn’t matter whether you use the address operator when calling or not.
- Book: lst-0034-book.cpp
- Godbolt: lst-0034-godb.cpp, https://godbolt.org/z/c9Eh346cq
- Listing 23.15: A class with “operator()” creates function objects.
- Book: lst-0035-book.cpp
- Godbolt: lst-0035-godb.cpp, https://godbolt.org/z/xvfvG8hrd
- Listing 23.16: A class with a normal method.
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/MfKzd8bxa
- Listing 23.17: With “operator<” as a function, you can only implement one sort order.
- Book: lst-0039-book.cpp
- Godbolt: lst-0039-godb.cpp, https://godbolt.org/z/3ch51ov87
- Listing 23.18: A no-frills functor with great utility.
- Book: lst-0041-book.cpp
- GodboltId:PebG9bn9K
- Book: lst-0042-book.cpp
- Godbolt: lst-0042-godb.cpp, https://godbolt.org/z/PebG9bn9K
- Listing 23.19: Many algorithms in the standard library also work with “operator<”.
- Book: lst-0046-book.cpp
- Godbolt: lst-0046-godb.cpp, https://godbolt.org/z/YKzsW49G8
- Listing 23.20: With the capture clause, you can access external variables in the lambda.
- Book: lst-0053-book.cpp
- Godbolt: lst-0053-godb.cpp, https://godbolt.org/z/eh6jnjK9z
- Listing 23.21: The capture clause can also contain references.
- Book: lst-0054-book.cpp
- Godbolt: lst-0054-godb.cpp, https://godbolt.org/z/j7qoMdG3n
- Listing 23.22: “mutable” makes value captures in lambdas mutable.
- Book: lst-0056-book.cpp
- Godbolt: lst-0056-godb.cpp, https://godbolt.org/z/zMWo69974
- Listing 23.23: If possible, better without mutable.
- Book: lst-0057-book.cpp
- Godbolt: lst-0057-godb.cpp, https://godbolt.org/z/8GxPMEc5o
- GodboltId:xnbvEx5Kc
- Book: lst-0060-book.cpp
- Godbolt: lst-0060-godb.cpp, https://godbolt.org/z/xnbvEx5Kc
- GodboltId:nenW8aM81
- Book: lst-0061-book.cpp
- Godbolt: lst-0061-godb.cpp, https://godbolt.org/z/nenW8aM81
- Listing 23.24: Concepts can be written in different ways.
- Book: lst-0062-book.cpp
- Godbolt: lst-0062-godb.cpp, https://godbolt.org/z/jP75nY4EW
- Listing 23.25: With concepts, you can restrict individual overloads.
- Book: lst-0063-book.cpp
- Godbolt: lst-0063-godb.cpp, https://godbolt.org/z/Kxrz5ETh6
- GodboltId:eaGre4bqr
- Book: lst-0065-book.cpp
- Godbolt: lst-0065-godb.cpp, https://godbolt.org/z/eaGre4bqr
- Listing 23.26: Specify additional conditions with requires.
- Book: lst-0066-book.cpp
- Godbolt: lst-0066-godb.cpp, https://godbolt.org/z/fxoo4h9Gj
- Listing 23.27: Define recurring requirements with concept.
- Book: lst-0067-book.cpp
- Godbolt: lst-0067-godb.cpp, https://godbolt.org/z/Tcxnr6jTM
- GodboltId:9qsGW6M8Y
- Book: lst-0068-book.cpp
- Godbolt: lst-0068-godb.cpp, https://godbolt.org/z/9qsGW6M8Y
- Listing 23.28: This is how you use concepts in a constexpr if.
- Book: lst-0069-book.cpp
- Listing 23.29: A class template takes a type as a formal parameter.
- Book: lst-0073-book.cpp
- Godbolt: lst-0073-godb.cpp, https://godbolt.org/z/jqzTMxYKv
- Listing 23.30: Method definitions outside the body of a class template are syntactically somewhat more complex.
- Book: lst-0075-book.cpp
- Godbolt: lst-0075-godb.cpp, https://godbolt.org/z/4fK5WdoG8
- Listing 23.31: Specializing class template methods like function templates.
- Book: lst-0076-book.cpp
- Godbolt: lst-0076-godb.cpp, https://godbolt.org/z/M6earoWMn
- Listing 23.32: This is how you create instances from a template class.
- Book: lst-0077-book.cpp
- Godbolt: lst-0077-godb.cpp, https://godbolt.org/z/9vP3o68bW
- Listing 23.33: Deduce template parameters from constructor arguments.
- Book: lst-0078-book.cpp
- Godbolt: lst-0078-godb.cpp, https://godbolt.org/z/YaEW5aTra
- Listing 23.34: You have been able to use make_ helper functions and auto for a long time.
- Book: lst-0079-book.cpp
- GodboltId:dMTnbT1v4
- Book: lst-0080-book.cpp
- Godbolt: lst-0080-godb.cpp, https://godbolt.org/z/dMTnbT1v4
- GodboltId:jbafeEdoW
- Book: lst-0081-book.cpp
- Godbolt: lst-0081-godb.cpp, https://godbolt.org/z/jbafeEdoW
- GodboltId:E89bav3rE
- Book: lst-0084-book.cpp
- Godbolt: lst-0084-godb.cpp, https://godbolt.org/z/E89bav3rE
- GodboltId:9rzsh5366
- Book: lst-0089-book.cpp
- Godbolt: lst-0089-godb.cpp, https://godbolt.org/z/9rzsh5366
- GodboltId:baPeoTbM8
- Book: lst-0090-book.cpp
- Godbolt: lst-0090-godb.cpp, https://godbolt.org/z/baPeoTbM8
- Listing 23.35: A template with a variable number of arguments.
- Book: lst-0091-book.cpp
- Godbolt: lst-0091-godb.cpp, https://godbolt.org/z/eenKej9sj
- GodboltId:8oYaWYnbx
- Book: lst-0097-book.cpp
- Godbolt: lst-0097-godb.cpp, https://godbolt.org/z/8oYaWYnbx
- Listing 23.36: Custom literal operators.
- Book: lst-0098-book.cpp
- Godbolt: lst-0098-godb.cpp, https://godbolt.org/z/cjx49ef19
- Listing 23.37: Which literal leads to which operator call?
- Book: lst-0099-book.cpp
- Godbolt: lst-0099-godb.cpp, https://godbolt.org/z/Mevoshb3o
- Listing 23.38: A template for literals of exact length two.
- Book: lst-0100-book.cpp
- Godbolt: lst-0100-godb.cpp, https://godbolt.org/z/5rdzn8YP4
- Listing 23.39: Recursive definition for arbitrary literal lengths.
- Book: lst-0101-book.cpp
- Godbolt: lst-0101-godb.cpp, https://godbolt.org/z/sbxojqjqs
- Listing 23.40: The new if constexpr saves function specializations.
- Book: lst-0102-book.cpp
- Godbolt: lst-0102-godb.cpp, https://godbolt.org/z/KvsGh4f1v
- Listing 23.41: Fold expressions make variadic templates simpler.
- Book: lst-0103-book.cpp
- Godbolt: lst-0103-godb.cpp, https://godbolt.org/z/cPoEjqzM7
- Listing 23.42: Whether preprocessed or raw is better depends on the application.
- Book: lst-0104-book.cpp
- Godbolt: lst-0104-godb.cpp, https://godbolt.org/z/Yd4sser5j