std::integral(3)

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

This is the std::integral(3) page from the C++ Standard Library (the header spells it C++ Standard Libary, and honestly? iconic typo energy πŸ’…), and bestie, it’s giving concept-cute.

πŸŽ€ NAME πŸŽ€

std::integral β€” std::integral. That’s the name, no notes, we move.

✨ SYNOPSIS ✨

Okay so first things first: this lil concept lives in the header <concepts>, and it’s been here since C++20.

Defined in header <concepts>
template< class T >                        (since C++20)
concept integral = std::is_integral_v<T>;

The concept integral<T> is satisfied if and only if T is an integral type. No cap, that’s the whole vibe check.

🌸 EXAMPLE 🌸

Run this code, bestie β€” it’s a whole overload moment:

       // Run this code

        #include <concepts>
        #include <iostream>

        void print(std::integral auto i)
        {
            std::cout << "Integral: " << i << '\n';
        }

        void print(auto x)
        {
            std::cout << "Non-integral: " << x << '\n';
        }

        int main()
        {
            std::cout << std::boolalpha;

            static_assert(std::integral<bool>);
            print(true);

            static_assert(std::integral<char>);
            print('o');

            static_assert(std::integral<int>);
            print(007);

            static_assert( ! std::integral<double> );
            print(2e2);

            static_assert( ! std::integral<decltype("")> );
            print("∫∫∫");
        }

πŸ“ OUTPUT πŸ“

The output is literally this, character for character:

        Integral: true
        Integral: o
        Integral: 7
        Non-integral: 200
        Non-integral: ∫∫∫

🌈 SEE ALSO 🌈

  • is_integral β€” checks if a type is an integral type (C++11) (class template)

mwah πŸ’‹ this lil page came from http://cppreference.com, version/date 2024.06.10, and it’s the std::integral(3) page β€” periodt. 🫢

πŸ“¦ where this page comes from