namespace std {
template<class T>
concept integral = is_integral_v<T>;
}
概要
integral
は、任意の型T
が整数型であることを表すコンセプトである。
例
#include <iostream>
#include <concepts>
#include <cstdint>
#include <type_traits>
template<std::integral T>
void f(const char* name) {
std::cout << name << " is integral" << std::endl;
}
template<typename T>
void f(const char* name) {
std::cout << name << " is not integral" << std::endl;
}
int main() {
f<bool>("bool");
f<int>("int");
f<std::size_t>("std::size_t");
f<std::uint32_t>("std::uint32_t");
f<char>("char");
f<char8_t>("char8_t");
std::cout << "\n";
f<int*>("int*");
f<int&>("int&");
f<std::integral_constant<int, 1>>("std::integral_constant<int, 1>");
}
31
f<std::integral_constant<int, 1>>("std::integral_constant<int, 1>");
#include <iostream>
#include <concepts>
#include <cstdint>
#include <type_traits>
template<std::integral T>
void f(const char* name) {
std::cout << name << " is integral" << std::endl;
}
template<typename T>
void f(const char* name) {
std::cout << name << " is not integral" << std::endl;
}
int main() {
f<bool>("bool");
出力
bool is integral
int is integral
std::size_t is integral
std::uint32_t is integral
char is integral
char8_t is integral
int* is not integral
int& is not integral
std::integral_constant<int, 1> is not integral
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: 10.1 ✅
- Visual C++: 2019 Update 3 ✅