std:: signed_integral
From cppreference.net
|
ヘッダーで定義
<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); // 符号付き test(0xFULL, "0xFULL"); // 符号なし test('A'); // プラットフォーム依存 test(true, "true"); // 符号なし test(4e-2, "4e-2"); // 非整数(16進浮動小数点数) test("∫∫"); // 非整数 }
出力例:
(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++23標準 (ISO/IEC 14882:2024):
-
- 18.4.7 算術コンセプト [concepts.arithmetic]
- C++20標準 (ISO/IEC 14882:2020):
-
- 18.4.7 算術コンセプト [concepts.arithmetic]
関連項目
|
(C++11)
|
型が整数型かどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型が符号付き算術型かどうかをチェックする
(クラステンプレート) |