Spec-Zone.ru › C++

std::floating_point

Определено в заголовочном файле <concepts>
template< class T >
concept floating_point = std::is_floating_point_v<T>;
(с C++20)

Концепция floating_point<T> выполняется тогда и только тогда, когда T является типом с плавающей точкой.

Пример

#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';
}

Вывод:

2.2
4.4
888

См. также

is_floating_point
(C++11)
проверяет, является ли тип типом с плавающей точкой
(шаблон класса)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/concepts/floating_point

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API