std::regular(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ std::regular πŸ¦‹

okay so this is the C++ Standard Libary manual page for std::regular(3) β€” yes bestie, the concept is literally named std::regular, and the NAME section is just her name twice. iconic behavior, no notes πŸ’…

πŸ’– NAME πŸ’–

std::regular - std::regular (self-titled queen, we love to see it πŸ‘‘)

✨ Synopsis ✨

Defined in header <concepts>.

template< class T >
(since C++20)
concept regular = std::semiregular<T> && std::equality_comparable<T>;

so the regular concept is the vibe check for a type being regular: the type is copyable, default constructible, and equality comparable. It’s satisfied by types that behave similarly to built-in types like int, and that are comparable with ==. slay βœ…

πŸŽ€ Example πŸŽ€

// Run this code β€” go off, bestie:

// Run this code

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

🌈 Output 🌈

Equal
4 4

πŸ‘‘ See also πŸ‘‘

  • semiregular β€” specifies that an object of a type can be copied, moved, swapped, and (C++20) default constructed. It’s a (concept), iykyk 🫢

🫢 that’s the whole page. source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::regular(3) β€” mwah, go be regular (the concept, not boring) πŸ’–βœ¨

πŸ“¦ where this page comes from