Type trait
A type trait is a compile-time facility that queries or transforms a type and produces a result representing the requested property or type.
Modern C, Third Edition
A type trait is a compile-time operation that queries a property of a type and produces a result representing that property.
- How it is used
- Enables efficient type-generic features by querying argument-type properties at compile time.
- How deep it goes
- Develops macro requirements and implementation strategies for constants, integer types, VLAs, and pointer qualifiers.
- Examples
- Uses tozero, tonull, isinteger, isvla, pointer-qualification tests, and a type-directed pow macro.
- What you can do after
- Build compile-time type-trait macros that return boolean integer constant expressions without evaluating their arguments.
Learn C++ by Example
A type trait is a compile-time facility that exposes a property or transformation of a C++ type.
- How it is used
- Uses type traits to interrogate types and check whether template-related requirements are satisfied.
- How deep it goes
- Defines traits through a clock-checking example and stops short of detailing trait implementation internals.
- Examples
- Demonstrates std::chrono::is_clock<int>::value as a false result for a non-clock type.
- What you can do after
- Evaluate whether a type satisfies named requirements by reading a trait's Boolean value.
Related concepts
- is_constructibleincludes · is_constructible is a C++ type trait that determines whether a type can be constructed from a specified set of argument types.
- _Genericused by · _Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
- typeof operatorused by · A typeof operator obtains type information about an operand or expression, yielding a type or a string describing its type depending on the language.
- type_traits headerused by · The type_traits header is the C++ standard library header that declares compile-time type property queries and transformations.
- special member functionmeasures · A special member function is a C++ member function with compiler-recognized semantics for object initialization, copying, moving, or destruction.
- type-trait variable templateused by · A type-trait variable template is a C++17 shorthand variable template exposing the Boolean value of a corresponding type trait.
Questions about type trait
What is type trait?
A type trait is a compile-time facility that queries or transforms a type and produces a result representing the requested property or type.
Which Manning books explain type trait?
Modern C, Third Edition and Learn C++ by Example.
What kinds of type trait are there?
Kinds of type trait include is_constructible.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

