名稱空間
變體
操作

std::unsigned_integral

來自 cppreference.com
< cpp‎ | 概念
定義於標頭檔案 <concepts>
template< class T >
concept unsigned_integral = std::integral<T> && !std::signed_integral<T>;
(C++20 起)

概念 unsigned_integral<T> 滿足當且僅當 T 是整數型別且 std::is_signed_v<T>false

目錄

[編輯] 注意

unsigned_integral<T> 可能由非 無符號整數型別 的型別滿足,例如 bool

[編輯] 示例

#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 算術概念 [concepts.arithmetic]
  • C++20 標準 (ISO/IEC 14882:2020)
  • 18.4.7 算術概念 [concepts.arithmetic]

[編輯] 另請參閱

檢查型別是否為整型
(類模板) [編輯]
(C++11)
檢查型別是否為有符號算術型別
(類模板) [編輯]