Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
josuttis_nm_c20_the_complete_guide.pdf
Скачиваний:
44
Добавлен:
27.03.2023
Размер:
5.85 Mб
Скачать

Chapter 20

New Type Traits

This chapter presents several type traits (and two low-level functions for types) that C++20 introduces in its standard library.

Table New type traits lists these new type traits of C++20 (all are defined in the namespace std).

Trait

 

Effect

is_bounded_array_v<T>

 

Yields true if type T is an array type with known extent

is_unbounded_array_v<T>

 

Yields true if type T is an array type with unknown extent

is_nothrow_convertible_v<T, T2>

 

Yields true if T is convertible to type T2 without throwing

is_layout_compatible_v<T1, T2>

 

Yields true if T1 is layout-compatible with type T2

is_pointer_interconvertible...

 

Yields true if a pointer to DerT can safely be

_base_of_v<BaseT, DerT>

 

converted to a pointer to its base type BaseT

remove_cvref_t<T>

 

Yields type T without reference, top-level const, volatile

unwrap_reference_t<T>

 

Yields the wrapped type of type T if it is a

 

 

std::reference_wrapper<> or otherwise T

unwrap_ref_decay_t<T>

 

Yields the wrapped type of type T if it is a

 

 

std::reference_wrapper<> or otherwise its decayed type

common_reference_t<T...>

 

Yields the common type of all types T...

 

 

to which you can assign a value

type_identity_t<T>

 

Yields type T as it is

iter_difference_t<T>

 

Yields the difference type of the incrementable/iterator type T

iter_value_t<T>

 

Yields the value/element type of the pointer/iterator type T

iter_reference_t<T>

 

Yields the reference type of the pointer/iterator type T

iter_rvalue_reference_t<T>

 

Yields the rvalue reference type of the pointer/iterator type T

is_clock_v<T>

 

Yields true if T is a clock type

compare_three_way_result_t<T>

 

Yields the type of comparing two values with operator <=>

 

Table 20.1. New type traits

641