std::regular

来自cppreference.com
< 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