std::numeri...::is_signed(3)
π 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 */βfalseboolβfalsecharβ implementation-definedsigned charβtrueunsigned charβfalsewchar_tβ implementation-definedchar8_t (since C++20)βfalsechar16_t (since C++11)βfalsechar32_t (since C++11)βfalseshortβtrueunsigned shortβfalseintβtrueunsigned intβfalselongβtrueunsigned longβfalselong long (since C++11)βtrueunsigned long long (since C++11)βfalsefloatβtruedoubleβtruelong doubleβtrue
<yellow>implementation-defined</yellow>forcharandwchar_tmeans 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms