名前空間
変種
操作

std::signed_integral

From cppreference.com
< cpp‎ | concepts
 
 
 
ヘッダ <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>は、符号付き整数型ではない型でも満たされる場合があります。例えば、charcharが符号付きであるシステム上)などです。

[編集]

#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++23標準 (ISO/IEC 14882:2024)
  • 18.4.7 Arithmetic concepts [concepts.arithmetic]
  • C++20 standard (ISO/IEC 14882:2020)
  • 18.4.7 Arithmetic concepts [concepts.arithmetic]

[編集] 関連項目

型が整数型であるかをチェックする
(クラステンプレート) [編集]
(C++11)
型が符号付き算術型であるかをチェックする
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)