std::incrementable_traits - cppreference.com
来自cppreference.com
| 在标头 |
||
template< class I > struct incrementable_traits {}; |
(1) | (C++20 起) |
template< class T > requires std::is_object_v<T> struct incrementable_traits<T*>; |
(2) | (C++20 起) |
template< class T > struct incrementable_traits<const T> : incrementable_traits<T> {}; |
(3) | (C++20 起) |
template< class T > requires requires { typename T::difference_type; } struct incrementable_traits<T>; |
(4) | (C++20 起) |
template< class T > requires (!requires { typename T::difference_type; }) && requires(const T& a, const T& b) { { a - b } -> std::integral; } struct incrementable_traits<T>; |
(5) | (C++20 起) |
计算类型 I 所关联的差类型,如果存在。程序可对由程序定义的类型特化 incrementable_traits。
1) 主模板是空结构体。
2) 对指针的特化。
提供的成员类型 difference_type 是 std::ptrdiff_t。
3) 对 const 限定类型的特化。
4) 对定义了公开可访问成员类型 difference_type 的类型的特化。
提供的成员类型 difference_type 是 T::difference_type。
5) 对未定义公开可访问成员类型 difference_type 但支持减法的类型的特化。
提供的成员类型 difference_type 是 std::make_signed_t<decltype(std::declval<T>() - std::declval<T>())>。隐式表达式变种规则(见后述)应用于表达式 a - b。
隐式表达式变种
使用了不修改某常量左值操作数的表达式的 requires 表达式,也会要求其隐式的表达式变种。