std::numeri...::is_signed(3)

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

πŸŽ€ std::numeri...::is_signed(3) πŸŽ€

okay so welcome to the <pink>std::numeri...::is_signed(3)</pink> page from the <purple>C++ Standard Libary</purple>, bestie ✨ this one is all about the is_signed` trait and it is lowkey iconic. no cap, it’s giving β€œis this type signed or not?” energy πŸ’…


πŸ’– NAME πŸ’–

std::numeric_limits::is_signed β€” std::numeric_limits::is_signed


πŸ¦‹ Synopsis πŸ¦‹

static const bool is_signed;      (until C++11)
static constexpr bool is_signed;  (since C++11)

The value of std::numeric_limits<T>::is_signed is <green>true</green> for all signed arithmetic types T and <red>false</red> for the unsigned types. This constant is meaningful for all specializations. periodt πŸ’«


🌈 Standard specializations 🌈

okay bestie, here’s the whole lineup of T and the value of std::numeric_limits<T>::is_signed β€” every single one, no skipping 🫢

  • /* non-specialized */ β€” false
  • bool β€” false
  • char β€” implementation-defined
  • signed char β€” true
  • unsigned char β€” false
  • wchar_t β€” implementation-defined
  • char8_t (since C++20) β€” false
  • char16_t (since C++11) β€” false
  • char32_t (since C++11) β€” false
  • short β€” true
  • unsigned short β€” false
  • int β€” true
  • unsigned int β€” false
  • long β€” true
  • unsigned long β€” false
  • long long (since C++11) β€” true
  • unsigned long long (since C++11) β€” false
  • float β€” true
  • double β€” true
  • long double β€” true
<yellow>implementation-defined</yellow> for char and wchar_t means the implementation gets to decide β€” that’s the vibe here πŸ’…

πŸ”₯ Example πŸ”₯

// Run this code

#include <iostream>
#include <iomanip>
#include <limits>

template<typename T>
struct test
{
    test(const char* name, int w = 15)
    {
        std::cout
            << std::left << std::setw(w)
            << (std::numeric_limits<T>::is_specialized ? name : "non-specialized")
            << " : "
            << (std::numeric_limits<T>::is_signed ? "" : "un") << "signed\n";
    }
};

int main()
{
    test<bool>{"bool"};
    test<char>{"char"};
    test<wchar_t>{"wchar_t"};
    test<char16_t>{"char16_t"};
    test<char32_t>{"char32_t"};
    test<float>{"float"};
    struct delusion{};
    test<delusion>{"delusion"};
    test<decltype(42)>{"decltype(42)"};
}

πŸ’¬ Possible output πŸ’¬

bool            : unsigned
char            : signed
wchar_t         : signed
char16_t        : unsigned
char32_t        : unsigned
float           : signed
non-specialized : unsigned
decltype(42)    : signed

πŸ‘‘ See also πŸ‘‘

  • is_signed β€” checks if a type is a signed arithmetic type (C++11) (class template)
  • is_integer β€” identifies integer types [static] (public static member constant)
  • is_exact β€” identifies exact types [static] (public static member constant)
  • is_bounded β€” identifies types that represent a finite set of values [static] (public static member constant)

mwah πŸ’‹ this page came from <pink>http://cppreference.com</pink>, dated <lavender>2024.06.10</lavender>, and it’s the <rainbow>std::numeri...::is_signed(3)</rainbow> manual page. bye bestie, go check those signed vibes πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from