- concepts[meta header]
- std[meta namespace]
- concept[meta id-type]
- cpp20[meta cpp]
namespace std {
template<class T>
concept signed_integral = integral<T> && is_signed_v<T>;
}
- integral[link /reference/concepts/integral.md]
- is_signed_v[link /reference/type_traits/is_signed.md]
signed_integral
は、任意の型T
が符号付き整数型であることを表すコンセプトである。
char
など、符号付整数型でなくてもsigned_integral
のモデルとなる型が存在する。
#include <iostream>
#include <concepts>
#include <cstdint>
#include <type_traits>
template<std::signed_integral T>
void f(const char* name) {
std::cout << name << " is signed_integral" << std::endl;
}
template<typename T>
void f(const char* name) {
std::cout << name << " is not signed_integral" << std::endl;
}
int main() {
f<int>("int");
f<std::int64_t>("std::int64_t");
f<int>("char");
std::cout << "\n";
f<bool>("bool");
f<std::size_t>("std::size_t");
f<std::uint32_t>("std::uint32_t");
f<char8_t>("char8_t");
f<int*>("int*");
f<int&>("int&");
f<std::integral_constant<int, 1>>("std::integral_constant<int, 1>");
}
- std::integral[color ff0000]
int is signed_integral
std::int64_t is signed_integral
char is signed_integral
bool is not signed_integral
std::size_t is not signed_integral
std::uint32_t is not signed_integral
char8_t is not signed_integral
int* is not signed_integral
int& is not signed_integral
std::integral_constant<int, 1> is not signed_integral
- C++20
- Clang: ??
- GCC: 10.1 [mark verified]
- Visual C++: 2019 Update 3 [mark verified]