Namespaces
Variants

std:: regular

From cppreference.net
Definiert im Header <concepts>
template < class T >
concept regular = std:: semiregular < T > && std:: equality_comparable < T > ;
(seit C++20)

Das regular Konzept spezifiziert, dass ein Typ regular ist, das heißt, er ist kopierbar, standardkonstruierbar und gleichheitsvergleichbar. Es wird von Typen erfüllt, die sich ähnlich wie eingebaute Typen wie int verhalten und die mit == vergleichbar sind.

Beispiel

#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';
}

Ausgabe:

Equal
4 4

Referenzen

  • C++23-Standard (ISO/IEC 14882:2024):
  • 18.6 Objektkonzepte [concepts.object]
  • C++20-Standard (ISO/IEC 14882:2020):
  • 18.6 Objektkonzepte [concepts.object]

Siehe auch

spezifiziert, dass ein Objekt eines Typs kopiert, verschoben, ausgetauscht und standardkonstruiert werden kann
(Konzept)