std::signed_integral
Определено в заголовке <concepts> | ||
|---|---|---|
template< class T > concept signed_integral = std::integral<T> && std::is_signed_v<T>; | (с C++20) |
Концепция signed_integral<T> удовлетворяется тогда и только тогда, когда T является целочисленным типом, а std::is_signed_v<T> является true.
Примечания
Концепция signed_integral<T> может быть удовлетворена типом, который не является целочисленным типом со знаком, например, char (в системе, где char имеет знак).
Пример
#include <concepts>
#include <iostream>
#include <string_view>
void test(std::signed_integral auto x, std::string_view text = "")
{
std::cout << text << " (" + (text == "") << x << ") is a signed integral\n";
}
void test(std::unsigned_integral auto x, std::string_view text = "")
{
std::cout << text << " (" + (text == "") << x << ") is an unsigned integral\n";
}
void test(auto x, std::string_view text = "")
{
std::cout << text << " (" + (text == "") << x << ") is non-integral\n";
}
int main()
{
test(42); // signed
test(0xFULL, "0xFULL"); // unsigned
test('A'); // platform-dependent
test(true, "true"); // unsigned
test(4e-2, "4e-2"); // non-integral (hex-float)
test("∫∫"); // non-integral
}Возможный вывод:
(42) is a signed integral 0xFULL (15) is an unsigned integral (A) is a signed integral true (1) is an unsigned integral 4e-2 (0.04) is non-integral (∫∫) is non-integral
См. также
|
(C++11) | проверяет, является ли тип целочисленным типом (шаблон класса) |
|
(C++11) | проверяет, является ли тип знаковым арифметическим типом (шаблон класса) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/concepts/signed_integral