- concepts[meta header]
- std[meta namespace]
- concept[meta id-type]
- cpp20[meta cpp]
namespace std {
template<class T>
concept integral = is_integral_v<T>;
}
- is_integral_v[link /reference/type_traits/is_integral.md]
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>");
}
- std::integral[color ff0000]
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 [mark verified]
- Visual C++: 2019 Update 3 [mark verified]