std::semiregular(3)
πΈ NAME πΈ
std::semiregular β std::semiregular. (Yes bestie, that's the whole name. It ate and left no crumbs. π)
okay so you're on the std::semiregular(3) page from the C++ Standard Libary β that's the spelling in the source, don't come for me π β and we're about to make this concept make sense. π«Ά
β¨ Synopsis β¨
Defined in header <concepts>:
template< class T >
concept semiregular = std::copyable<T> &&
std::default_initializable<T>;
(since C++20) β yes, it's that era. π
The semiregular concept specifies that a type is both copyable and default constructible. It is satisfied by types that behave similarly to built-in types like int, except that they need not support comparison with ==. No cap, that's the whole requirement. π
π Example π
// Run this code
#include <concepts>
#include <iostream>
template<std::semiregular T>
// Credit Alexander Stepanov
// concepts are requirements on T
// Requirement on T: T is semiregular
// T a(b); or T a = b; => copy constructor
// T a; => default constructor
// a = b; => assignment
struct Single
{
T value;
// Aggregation initialization for Single behaves like following constructor:
// explicit Single(const T& x) : value(x) {}
// Implicitly declared special member functions behave like following definitions,
// except that they may have additional properties:
// Single(const Single& x) : value(x.value) {}
// Single() {}
// ~Single() {}
// Single& operator=(const Single& x) { value = x.value; return *this; }
// comparison operator is not defined; it is not required by `semiregular` concept
// bool operator==(Single const& other) const = delete;
};
void print(std::semiregular auto x)
{
std::cout << x.value << '\n';
}
int main()
{
Single<int> myInt1{4}; // aggregate initialization: myInt1.value = 4
Single<int> myInt2(myInt1); // copy constructor
Single<int> myInt3; // default constructor
myInt3 = myInt2; // copy assignment operator
// myInt1 == myInt2; // Error: operator== is not defined
print(myInt1); // ok: Single<int> is a `semiregular` type
print(myInt2);
print(myInt3);
} // Single<int> variables are destroyed here
β Output β
4
4
4
π See also π
regularβ specifies that a type isregular, that is, it is bothsemiregularandequality_comparable(C++20) (concept). iconique. π
okay that's the page, bestie π«Ά β source/version/date tea: http://cppreference.com, 2024.06.10, and the page is std::semiregular(3). byeeee π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms