namespace std {
template <class T>
concept floating_point = is_floating_point_v<T>;
}
概要
floating_point
は、任意の型T
が浮動小数点数型であることを表すコンセプトである。
例
#include <iostream>
#include <concepts>
template<std::floating_point T>
void f(const char* name) {
std::cout << name << " is floating point" << std::endl;
}
template<typename T>
void f(const char* name) {
std::cout << name << " is not floating point" << std::endl;
}
int main() {
f<float>("float");
f<double>("double");
f<long double>("long double");
f<const double>("const double");
f<volatile double>("volatile double");
std::cout << "\n";
f<bool>("bool");
f<int>("int");
f<std::size_t>("std::size_t");
f<double*>("double*");
f<double&>("double&");
}
出力
float is floating point
double is floating point
long double is floating point
const double is floating point
volatile double is floating point
bool is not floating point
int is not floating point
std::size_t is not floating point
double* is not floating point
double& is not floating point
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: 10.1 ✅
- Visual C++: 2019 Update 5 ✅