std::numeri...::is_integer(3)
π NAME
okay so bestie, welcome to std::numeric_limits::is_integer β like, the whole page is literally just std::numeric_limits::is_integer, and ngl the manual name at the top is std::numeri...::is_integer(3) because even the manpage got truncation energy. anyway. this is our little corner of the C++ Standard Library and it's lowkey iconic β¨
β¨ SYNOPSIS
the way this is literally just one bool that changed its outfit in C++11:
static const bool is_integer; (until C++11)
static constexpr bool is_integer; (since C++11)
so, the tea: the value of std::numeric_limits<T>::is_integer is true for all integer arithmetic types T and false otherwise. and this constant is meaningful for all specializations β no "sorry not applicable" nonsense, it always has something to say π
π STANDARD SPECIALIZATIONS
here's the vibe check for every T, matching up with the value of std::numeric_limits<T>::is_integer:
/* non-specialized */βfalseboolβtruecharβtruesigned charβtrueunsigned charβtruewchar_tβtruechar8_t(since C++20) βtruechar16_t(since C++11) βtruechar32_t(since C++11) βtrueshortβtrueunsigned shortβtrueintβtrueunsigned intβtruelongβtrueunsigned longβtruelong long(since C++11) βtrueunsigned long long(since C++11) βtruefloatβfalsedoubleβfalselong doubleβfalse
okay so the pattern is giving "if it's whole-number coded it's true, if it's floating-point coded it's false" π¦ and bool is in the true club, which honestly? deserved π
π₯ EXAMPLE
run this code, bestie, it's all static_assert so if it compiles you already won:
// Run this code
#include <cstddef>
#include <cstdint>
#include <limits>
static_assert
(
std::numeric_limits<bool>::is_integer
&& std::numeric_limits<std::size_t>::is_integer
&& std::numeric_limits<std::int32_t>::is_integer
&& std::numeric_limits<std::int64_t>::is_integer
&& std::numeric_limits<decltype(42)>::is_integer
&& !std::numeric_limits<int*>::is_integer
&& !std::numeric_limits<float>::is_integer
&& !std::numeric_limits<double>::is_integer
&& !std::numeric_limits<long double>::is_integer
&& !std::numeric_limits<decltype([](){})>::is_integer // P0315R4
);
int main() {}
the way std::numeric_limits<decltype(42)>::is_integer is just int in a trench coat and still ate π and yes, int* and the lambda (// P0315R4) are very much not integers, no cap.
π SEE ALSO
the squad, all linked up:
is_integralβ checks if a type is an integral type, (C++11) (class template)is_signedβ identifies signed 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)
okay that's the whole page, you ate that fr fr π«Ά this iconic little slice of documentation came to you from cppreference.com, dated 2024.06.10, and it was called std::numeri...::is_integer(3) β mwah, periodt ππΈ
π¦ 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