std::floating_point(3)
π NAME π
Okay bestie, welcome to the std::floating_point(3) manual page β the C++ concept thatβs basically a vibe check for floating-point types. π
std::floating_point β std::floating_point. (The NAME line literally goes std::floating_point - std::floating_point, and honestly? Mirror moment. We love that for us.)
β¨ Synopsis β¨
Defined in header <concepts> β thatβs where this cutie lives.
template< class T > (since C++20)
concept floating_point = std::is_floating_point_v<T>;
The concept floating_point<T> is satisfied if and only if T is a floating-point type. Thatβs the whole rule. No cap.
π Example π
Run this code, bestie:
#include <concepts>
#include <iostream>
#include <type_traits>
constexpr std::floating_point auto x2(std::floating_point auto x)
{
return x + x;
}
constexpr std::integral auto x2(std::integral auto x)
{
return x << 1;
}
int main()
{
constexpr auto d = x2(1.1);
static_assert(std::is_same_v<double const, decltype(d)>);
std::cout << d << '\n';
constexpr auto f = x2(2.2f);
static_assert(std::is_same_v<float const, decltype(f)>);
std::cout << f << '\n';
constexpr auto i = x2(444);
static_assert(std::is_same_v<int const, decltype(i)>);
std::cout << i << '\n';
}
π¦ Output π¦
2.2
4.4
888
π See also π
is_floating_pointβ checks if a type is a floating-point type (C++11) (class template).
mwah π source/version: http://cppreference.com, date: 2024.06.10, manual: std::floating_point(3). byeee, go slay some templates π«Άβ¨
π¦ 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