Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::numeric_limits<T>::is_signed

      From cppreference.com
      <cpp‎ |types‎ |numeric limits
       
       
      Utilities library
       
       
      std::numeric_limits
      Static constants
      numeric_limits::is_signed
      Static member functions
      Helper types
       
      staticconstbool is_signed;
      (until C++11)
      staticconstexprbool is_signed;
      (since C++11)

      The value ofstd::numeric_limits<T>::is_signed istrue for all signed arithmetic typesT andfalse for the unsigned types. This constant is meaningful for all specializations.

      [edit]Standard specializations

      T value ofstd::numeric_limits<T>::is_signed
      /* non-specialized */false
      boolfalse
      char implementation-defined
      signedchartrue
      unsignedcharfalse
      wchar_t implementation-defined
      char8_t(since C++20)false
      char16_t(since C++11)false
      char32_t(since C++11)false
      shorttrue
      unsignedshortfalse
      inttrue
      unsignedintfalse
      longtrue
      unsignedlongfalse
      longlong(since C++11)true
      unsignedlonglong(since C++11)false
      floattrue
      doubletrue
      longdoubletrue

      [edit]Example

      Run this code
      #include <iostream>#include <iomanip>#include <limits> template<typename T>struct test{    test(constchar* name,int w=15){std::cout<<std::left<<std::setw(w)<<(std::numeric_limits<T>::is_specialized? name:"non-specialized")<<" : "<<(std::numeric_limits<T>::is_signed?"":"un")<<"signed\n";}}; int main(){    test<bool>{"bool"};    test<char>{"char"};    test<wchar_t>{"wchar_t"};    test<char16_t>{"char16_t"};    test<char32_t>{"char32_t"};    test<float>{"float"};struct delusion{};    test<delusion>{"delusion"};    test<decltype(42)>{"decltype(42)"};}

      Possible output:

      bool            : unsignedchar            : signedwchar_t         : signedchar16_t        : unsignedchar32_t        : unsignedfloat           : signednon-specialized : unsigneddecltype(42)    : signed

      [edit]See also

      (C++11)
      checks if a type is a signed arithmetic type
      (class template)[edit]
      [static]
      identifies integer types
      (public static member constant)[edit]
      [static]
      identifies exact types
      (public static member constant)[edit]
      [static]
      identifies types that represent a finite set of values
      (public static member constant)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/numeric_limits/is_signed&oldid=148374"

      [8]ページ先頭

      ©2009-2025 Movatter.jp