std:: floating_point
From cppreference.net
C++
Concepts library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||
|
헤더에 정의됨
<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
참고문헌
- C++23 표준 (ISO/IEC 14882:2024):
-
- 18.4.7 산술 개념 [concepts.arithmetic]
- C++20 표준 (ISO/IEC 14882:2020):
-
- 18.4.7 산술 개념 [concepts.arithmetic]
참고 항목
|
(C++11)
|
타입이 부동소수점 타입인지 확인합니다
(클래스 템플릿) |