liveBook · Manning

Type-trait variable template

As explained in Learn C++ by Example

A type-trait variable template is a C++17 shorthand variable template exposing the Boolean value of a corresponding type trait.

A type-trait variable template is the C++17 shorthand for reading a type trait’s Boolean value. Instead of writing std::is_constructible<Blob>::value, write std::is_constructible_v<Blob>. Both forms test a type at compile time; the _v helper removes the need to spell out value. section 6.1.4

Checking a polymorphic base class

A set of static assertions can check the special member functions of Race::Blob: it is not default-constructible, copy-constructible, copy-assignable, move-constructible, or move-assignable, but it is destructible. These checks turn type properties into compile-time requirements.

How Learn C++ by Example covers it

How deep it goes
Defines the _v shorthand and demonstrates static assertions, while deferring broader type-trait coverage to the library.
Examples
Uses Blob construction checks and static assertions for destructibility, copying, assignment, and moving.
What it assumes
Assumes templates and type traits, while contrasting the C++11 ::value interface with C++17 variable-template helpers.
What you can do after
Evaluate type properties with concise _v expressions and enforce them through static assertions.
How it connects
Connects variable templates with type traits, templates, concepts, special member functions, and compile-time metaprogramming.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.