std::regular
来自cppreference.com
<tbody>
</tbody>
| 在标头 <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 Object concepts [concepts.object]
- C++20 标准(ISO/IEC 14882:2020):
- 18.6 Object concepts [concepts.object]
参阅
(C++20) |
指定能赋值、移动、交换及默认构造一个类型的对象 (概念) |