The <type_traits> header lets templates inspect type properties at compile time. Each trait receives a type and exposes a Boolean result describing whether an operation is supported. section 6.1.4
Common checks include:
- is_constructible checks whether a type can be constructed, optionally with specified argument types. section 6.1.4
- is_default_constructible, is_destructible, and the copy or move construction and assignment traits inspect special member functions. section 6.1.4
- is_invocable checks whether a type can be called, providing a type-trait counterpart to the invocable concept. section 6.1.4
Checking an abstract type
Include <type_traits> and use static_assert to verify Blob's properties. The _v form, introduced in C++17, directly yields the Boolean value; the older form uses ::value. section 6.1.4
Listing 6.10 Type traits to check for special member functions
#include <type_traits>
void check_properties()
{
... #1
static_assert(
!std::is_default_constructible_v<Race::Blob>
); #2
static_assert(
std::is_destructible_v<Race::Blob>
); #2
static_assert(
!std::is_copy_constructible_v<Race::Blob>
); #2
static_assert(
!std::is_copy_assignable_v<Race::Blob>
); #2
static_assert(
!std::is_move_constructible_v<Race::Blob>
); #2
static_assert(
!std::is_move_assignable_v<Race::Blob>
); #2
static_assert(
std::has_virtual_destructor_v<Race::Blob>
); #3
}
The listing checks whether Blob is default constructible, destructible, copy constructible, copy assignable, move constructible, and move assignable. section 6.1.4
