std::regular
来自 cppreference.cn
定义于头文件 <concepts> |
||
template< class T > concept regular = std::semiregular<T> && std::equality_comparable<T>; |
(since C++20) | |
regular
概念指定类型是regular,即它是可复制的、默认可构造的以及可进行相等性比较的。它由行为类似于内置类型(如 int
)且可以使用 ==
进行比较的类型满足。
[edit] 示例
运行此代码
#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
[edit] 参考
- C++23 标准 (ISO/IEC 14882:2024)
- 18.6 对象概念 [concepts.object]
- C++20 标准 (ISO/IEC 14882:2020)
- 18.6 对象概念 [concepts.object]
[edit] 参见
(C++20) |
指定类型对象可以被复制、移动、交换和默认构造 (概念) |