listings-Chap13-README.md
Listings of Chap13.docx
This is linked summary of the listings. You can also view it on one page.
- Listing 13.1: You define a namespace with “namespace”.
- Book: lst-0001-book.cpp
- Godbolt: lst-0001-godb.cpp, https://godbolt.org/z/qo6W3bh5d
- Listing 13.2: In separate namespaces, you can define the same operators.
- Book: lst-0005-book.cpp
- Listing 13.3: An anonymous namespace makes definitions local to the current file.
- Book: lst-0006-book.cpp
- Godbolt: lst-0006-godb.cpp, https://godbolt.org/z/e3d55zvT8
- GodboltId:zfYzPjqrW
- Book: lst-0007-book.cpp
- Godbolt: lst-0007-godb.cpp, https://godbolt.org/z/zfYzPjqrW
- Listing 13.4: All instances share their “static” data fields and methods.
- Book: lst-0009-book.cpp
- Godbolt: lst-0009-godb.cpp, https://godbolt.org/z/n4e8xdEGj
- GodboltId:b9arcEMM1
- Book: lst-0011-book.cpp
- Godbolt: lst-0011-godb.cpp, https://godbolt.org/z/b9arcEMM1
- Listing 13.5: A local static variable is initialized once and reused thereafter.
- Book: lst-0012-book.cpp
- Godbolt: lst-0012-godb.cpp, https://godbolt.org/z/h5qond6db
- Listing 13.6: The Meyers Singleton.
- Book: lst-0013-book.cpp
- Listing 13.7: The identifiers of an inline namespace also go into its surrounding namespace.
- Book: lst-0014-book.cpp
- Godbolt: lst-0014-godb.cpp, https://godbolt.org/z/115M1csEE
- GodboltId:WTWxYa3rd
- Book: lst-0024-book.cpp
- Godbolt: lst-0024-godb.cpp, https://godbolt.org/z/WTWxYa3rd
- Listing 13.8: Local constants of a file fit well into an anonymous namespace.
- Book: lst-0029-book.cpp
- Godbolt: lst-0029-godb.cpp, https://godbolt.org/z/bxPaz9aW5
- GodboltId:fM4nsx9GP
- Book: lst-0030-book.cpp
- Godbolt: lst-0030-godb.cpp, https://godbolt.org/z/fM4nsx9GP
- Listing 13.9: Although the return type is marked with ‘const’ here, it has no effect because it is always copied.
- Book: lst-0031-book.cpp
- Godbolt: lst-0031-godb.cpp, https://godbolt.org/z/98x3YsnKc
- Listing 13.10: Constant references in returns.
- Book: lst-0032-book.cpp
- Godbolt: lst-0032-godb.cpp, https://godbolt.org/z/3EG1ovcev
- Listing 13.11: References can be returned as constant and nonconstant.
- Book: lst-0033-book.cpp
- Godbolt: lst-0033-godb.cpp, https://godbolt.org/z/9MTj3rP5d
- GodboltId:4dnTs4vPx
- Book: lst-0036-book.cpp
- Godbolt: lst-0036-godb.cpp, https://godbolt.org/z/4dnTs4vPx
- Listing 13.12: Some expressions must be known at compile time.
- Book: lst-0037-book.cpp
- Godbolt: lst-0037-godb.cpp, https://godbolt.org/z/E6MWxY1f7
- Listing 13.13: Whether the compiler can use a constant in a constant expression is not always immediately apparent.
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/xPzcWPdMa
- Listing 13.14: With “constexpr”, the compiler sees when an expression is not computable early.
- Book: lst-0040-book.cpp
- GodboltId:Yv85s9T6v
- Book: lst-0041-book.cpp
- Godbolt: lst-0041-godb.cpp, https://godbolt.org/z/Yv85s9T6v
- Listing 13.15: With “if constexpr”, you can decide at compile time what code will be executed.
- Book: lst-0044-book.cpp
- Godbolt: lst-0044-godb.cpp, https://godbolt.org/z/zMbnYzo17
- Listing 13.16: “if constexpr” also works with “else”.
- Book: lst-0045-book.cpp
- Godbolt: lst-0045-godb.cpp, https://godbolt.org/z/eo468MvMo
- GodboltId:44KMf1fWr
- Book: lst-0046-book.cpp
- Godbolt: lst-0046-godb.cpp, https://godbolt.org/z/44KMf1fWr
- Listing 13.17: With “consteval”, you can execute functions at compile time.
- Book: lst-0047-book.cpp
- Godbolt: lst-0047-godb.cpp, https://godbolt.org/z/v3x7nGs3f
- Listing 13.18: Even more complex functions can be computed at compile time with “consteval”.
- Book: lst-0048-book.cpp
- Godbolt: lst-0048-godb.cpp, https://godbolt.org/z/Wbr7n8M4q
- Listing 13.19: The compiler determines whether the call can be evaluated at compile time in the given context.
- Book: lst-0049-book.cpp
- Godbolt: lst-0049-godb.cpp, https://godbolt.org/z/7KWqTPo1K
- Listing 13.20: “mutable” makes a data field in const methods mutable.
- Book: lst-0051-book.cpp
- Godbolt: lst-0051-godb.cpp, https://godbolt.org/z/sPorKnEbd
- Listing 13.21: “const” with containers.
- Book: lst-0052-book.cpp
- Godbolt: lst-0052-godb.cpp, https://godbolt.org/z/GE5v6Ea8x
- Listing 13.22: x and y can somehow be changed from outside.
- Book: lst-0053-book.cpp