C++ / a working model

BOOK / SOURCE & READING RECORD

Advanced C++ Metaprogramming

Davide Di Gennaro

2011 CreateSpace edition, ISBN 9781460966167 (not the differently titled 2015 Apress book)

READING EVIDENCE / Partial text read

Advanced C++ Metaprogramming

Actually finished the two-page sample of §5.2.2 Concept traits provided by the author, and pages 405–408 of the bonus-chapter PDF (§9.3.2 ending and §9.3.3 More on the double wrapper technique). The bonus file is not a whole chapter; the range is not exaggerated based on the name. The rest of the main text was not obtained; the table of contents was only used to check structure, and the retail and Google Books pages have only metadata and were not treated as main text.

Edition, actual reading range, and original sources →

Sources

Syntax can be adapted; semantics still must be agreed

Author sample §5.2.2 Concept traits, two pages; bonus §9.3.3, book pages 405–408

The Concept traits sample shows an easily overlooked fact: a call expression that looks the same may be fulfilled by a static function, a function object, construction, or conversion. What generic code should really depend on is the effect that follows once the expression is valid, not an imagined assumption that the other party used a particular kind of declaration. This freedom also needs bounds; hiding resource release inside an implicit conversion may demonstrate language capability, but it makes code review hard to see side effects. Another bonus sample uses a classic C++ wrapper to prevent mixing different enumerations; today one usually just chooses enum class. My modern trade-off is to write the call shape with requires, adapt external types with a few explicit traits, and describe semantics that concepts cannot prove with documentation and assertions. The historical concept traits here cannot be called the same language feature as C++20 concepts.

Related fundamentals

Type traits and if constexpr compile-time branchingConcepts and requires: Constraining Callable InterfacesTemplate deduction: match parameters first, then instantiate code

Original practice →