std::unsigned_integral(3)

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

okay so this is the std::unsigned_integral(3) page from the C++ Standard Libary manual, and it's lowkey giving β€œis this type unsigned-integral?” main character energy πŸ’–βœ¨

✨ NAME ✨

std::unsigned_integral β€” that’s the whole name, bestie: std::unsigned_integral. No extra subtitle, no side quest. πŸ’…

🌸 Synopsis 🌸

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

The concept unsigned_integral<T> is satisfied if and only if T is an integral type and std::is_signed_v<T> is false. no cap, that's the whole vibe check 🫢

πŸ’… Notes πŸ’…

Bestie, listen: unsigned_integral<T> may be satisfied by a type that is not an unsigned integer type β€” for example, bool. yes, bool is out here sneaking into the unsigned-integral party πŸ™ˆπŸ’€

πŸŽ€ Example πŸŽ€

// Run this code

#include <concepts>
#include <iostream>
#include <string_view>

void test(std::signed_integral auto x, std::string_view text = "")
{
    std::cout << text << " (" + (text == "") << x << ") is a signed integral\n";
}

void test(std::unsigned_integral auto x, std::string_view text = "")
{
    std::cout << text << " (" + (text == "") << x << ") is an unsigned integral\n";
}

void test(auto x, std::string_view text = "")
{
    std::cout << text << " (" + (text == "") << x << ") is non-integral\n";
}

int main()
{
    test(42);               // signed
    test(0xFULL, "0xFULL"); // unsigned
    test('A');              // platform-dependent
    test(true, "true");     // unsigned
    test(4e-2, "4e-2");     // non-integral (hex-float)
    test("∫∫");             // non-integral
}

✨ Possible output ✨

(42) is a signed integral
0xFULL (15) is an unsigned integral
(A) is a signed integral
true (1) is an unsigned integral
4e-2 (0.04) is non-integral
(∫∫) is non-integral

πŸ‘‘ See also πŸ‘‘

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

source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::unsigned_integral(3) β€” mwah, go check your integral vibes, bestie πŸ’–πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from