std::common_with
定义于头文件 <concepts> |
||
template< class T, class U > concept common_with = |
(自 C++20 起) | |
概念 common_with<T, U>
指定了两种类型 T
和 U
共享一个公共类型 (由 std::common_type_t 计算得出),它们都可以转换为该类型。
内容 |
[编辑] 语义要求
类型 T 和 U 仅当在给定 保持相等性 表达式 t1
、t2
、u1
和 u2
时才std::common_with<T, U> 建模,其中 decltype((t1)) 和 decltype((t2)) 均为 T
,且 decltype((u1)) 和 decltype((u2)) 均为 U
,
- std::common_type_t<T, U>(t1) 等于 std::common_type_t<T, U>(t2) 当且仅当
t1
等于t2
;并且 - std::common_type_t<T, U>(u1) 等于 std::common_type_t<T, U>(u2) 当且仅当
u1
等于u2
。
换句话说,转换为公共类型必须保持相等性。
[编辑] 相等性保持
标准库概念的 requires 表达式 中声明的表达式需要是保持相等性的(除非另有说明)。
[编辑] 参考
- C++23 标准 (ISO/IEC 14882:2024)
- 18.4.6 概念
common_with
[concept.common]
- 18.4.6 概念
- C++20 标准 (ISO/IEC 14882:2020)
- 18.4.6 概念
common_with
[concept.common]
- 18.4.6 概念
[编辑] 参见
(C++11) |
确定一组类型的公共类型 (类模板) |
确定一组类型的公共引用类型 (类模板) | |
(C++20) |
指定两种类型共享一个公共引用类型 (概念) |