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

642

Chapter 20: New Type Traits

The following sections discuss these traits in detail, except for the following traits:

std::is_clock_v<> is discussed in the section about new chrono features.

std::compare_three_way_result_t<> is discussed in the section about the new three-way comparisons.

Note that in addition, the type trait std::is_pod<> was deprecated with C++20.

20.1New Type Traits for Type Classification

20.1.1 is_bounded_array_v<> and is_unbounded_array_v

std::is_bounded_array_v<T> std::is_unbounded_array_v<T>

yield whether type T is a bounded/unbounded array (extent known/unknown). For example:

int a[5];

 

std::is_bounded_array_v<decltype(a)>

// true

std::is_unbounded_array_v<decltype(a)>

// false

extern int b[];

 

std::is_bounded_array_v<decltype(b)>

// false

std::is_unbounded_array_v<decltype(b)>

// true

20.2New Type Traits for Type Inspection

20.2.1 is_nothrow_convertible_v<> std::is_nothrow_convertible_v<From, To>

yields whether type From is convertible to type To with the guarantee not to throw any exception.

For example:

 

// char* to std::string:

 

std::is_convertible_v<char*, std::string>

// true

std::is_nothrow_convertible_v<char*, std::string>

// false

// std::string to std::string_view:

 

std::is_convertible_v<std::string, std::string_view>

// true

std::is_nothrow_convertible_v<std::string, std::string_view>

// true