C++ 参考手册

位置:首页 > C++ 参考手册 >概念库 (C++20) > std::semiregular

定义于头文件 <concepts>
template <class T>
concept semiregular = std::copyable<T> && std::default_initializable<T>;
(C++20 起)

semiregular 概念指定类型既为可复制亦为可默认构造。表现类似如 int 的内建类型的类型满足它,除了它们不需要支持以 == 比较。

示例

#include <concepts>
#include <iostream>
 
template<std::semiregular T>
struct Single {
    T value;
};
 
int main()
{
    Single<int> myInt1{4};
    Single<int> myInt2;
    myInt2 = myInt1;
 
    std::cout << myInt1.value << ' ' << myInt2.value << '\n';
}

输出:

4 4