std::regular
来自 cppreference.cn
< cpp | 概念 (concepts)
定义于头文件 <concepts> |
||
template< class T > concept regular = std::semiregular<T> && std::equality_comparable<T>; |
(C++20 起) | |
regular
概念指定一个类型是*正则*的,也就是说,它是可拷贝的、可默认构造的,并且可相等比较。它由行为类似于 int 等内置类型,并且可用 ==
比较的类型所满足。
[编辑] 示例
运行此代码
#include <concepts> #include <iostream> template<std::regular T> struct Single { T value; friend bool operator==(const Single&, const Single&) = default; }; int main() { Single<int> myInt1{4}; Single<int> myInt2; myInt2 = myInt1; if (myInt1 == myInt2) std::cout << "Equal\n"; std::cout << myInt1.value << ' ' << myInt2.value << '\n'; }
输出
Equal 4 4
[编辑] 参考资料
- C++23 标准 (ISO/IEC 14882:2024)
- 18.6 对象概念 [concepts.object]
- C++20 标准 (ISO/IEC 14882:2020)
- 18.6 对象概念 [concepts.object]
[编辑] 参阅
(C++20) |
指定类型的对象可以被复制、移动、交换和默认构造 (概念) |