std::regular
Определено в заголовке <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++20) | определяет, что объект типа может быть скопирован, перемещен, поменян местами и создан по умолчанию (концепция) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/concepts/regular