<type_traits>

類模板
<type_traits>

std::is_floating_point

template <class T> struct is_floating_point;
浮點數型別判斷

Trait 類,用於判斷 T 是否為浮點數型別。

它繼承自 integral_constant,並根據T為浮點數型別

基本浮點數型別
float
double
long double

此類將所有基本浮點型別(以及它們的別名)視為浮點數型別,無論其 constvolatile 限定如何。

模板引數

T
一個型別。

成員型別

繼承自 integral_constant
成員型別定義
value_typebool
型別true_type 或 false_type

成員常量

繼承自 integral_constant
成員常量定義
truefalse

成員函式

繼承自 integral_constant

示例

1
2
3
4
5
6
7
8
9
10
11
12
// is_floating_point example
#include <iostream>
#include <type_traits>

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_floating_point:" << std::endl;
  std::cout << "int: " << std::is_floating_point<int>::value << std::endl;
  std::cout << "float: " << std::is_floating_point<float>::value << std::endl;
  std::cout << "const double: " << std::is_floating_point<const double>::value << std::endl;
  return 0;
}

輸出
is_floating_point:
int: false
float: true
const double: true


另見