Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      is-integer-like ,is-signed-integer-like

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      is-integer-like
      is-signed-integer-like
      (C++20)(C++20)
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
      template<class T>
      constexprbool/*is-integer-like*/=/* see description */;
      (1)(since C++20)
      (exposition only*)
      template<class T>
      constexprbool/*is-signed-integer-like*/=/* see description */;
      (2)(since C++20)
      (exposition only*)
      1)/*is-integer-like*/<T> istrue if and only ifT is an integer-like type.
      2)/*is-signed-integer-like*/<T> istrue if and only ifT is a signed-integer-like type.

      Contents

      [edit]Integer-class type

      A typeT is aninteger-class type if it is in a set of implementation-defined types that behave asinteger types do, as definedbelow. An integer-class type is not necessarily aclass type.

      An integer-class type can represent\(\scriptsize 2^N \)2N
      consecutive integers, whereN, a positive integer, is called thewidth of the integer-class type.

      An integer-class type is either signed or unsigned:

      • Asigned integer class type can represent all integers in[\(\scriptsize -2^{N-1} \)-2N-1
        \(\scriptsize 2^{N-1}-1 \)2N-1
        -1
        ]
        , whereN is greater than the width of every signed integral type.
      • Anunsigned integer class type can represent all integers in[\(\scriptsize 0 \)0\(\scriptsize 2^N-1 \)2N
        -1
        ]
        , whereN is greater than the width of every unsigned integral type.

      All integer-class types modelregular andthree_way_comparable<std::strong_ordering>.

      Avalue-initialized object of integer-class type has value0.

      An expressionE of integer-class typeT iscontextually convertible tobool as if bybool(E!= T(0)).

      [edit]Integer-like type

      A type other than (possibly cv-qualified)bool isinteger-like if it modelsintegral or if it is an integer-class type.

      • An integer-like type issigned-integer-like if it modelssigned_integral or if it is a signed-integer-class type.
      • An integer-like type isunsigned-integer-like if it modelsunsigned_integral or if it is an unsigned-integer-class type.

      [edit]Required behaviors

      Expressions of integer-class type are explicitly convertible to any integer-like type, and implicitly convertible to any integer-class type of equal or greater width and the same signedness. Expressions of integral type are both implicitly and explicitly convertible to any integer-class type. Conversions between integral and integer-class types and between two integer-class types do not exit via an exception. The result of such a conversion is the unique value of the destination type that is congruent to the source modulo\(\scriptsize 2^N \)2N
      , whereN is the width of the destination type.

      LetInt<T> denote the following type:

      • IfT is an integer-class type,Int<T> is a unique hypotheticalextended integer type of the same signedness with the same width asT.
      • IfT is an integral type, letInt<T> is the same type asT.

      Given the following types, values and operators:

      Type Definition
      IC an integer-class type
      IL an integer-like type
      Value Definition
      a an object of typeIC
      b an object of typeIL
      c an lvalue of an integeral type
      x an object of typeInt<IC> that represent the same value asa
      y an object of typeInt<IL> that represent the same value asb
      Operator Definition
      @= one of+=,-=,*=,/=,%=,&=,|=,^=,<<= and>>=
      @ one of+,-,*,/,%,&,|,^,<<,>>,&&,||,==,!=,<,>,<=,>=,<=> and,

      The following expressions must be well-formed and have their specified result and effects if the specified conditions are satisfied:

       Expression           Condition          ResultEffects
      a++No conditiona prvalue of typeIC whose value is equal to that ofa prior to the evaluationmodifies the value ofa by adding1 to it
      a--modifies the value ofa by subtracting1 to it
      ++aexpression-equivalent toa+=1
      --aexpression-equivalent toa-=1
      &aexpression-equivalent tostd::addressof(a)
      !a!x is well-formedsame as!x
      +a+x is well-formedsame as+x, but has typeICsame as+x
      -a-x is well-formedsame as-x, but has typeICsame as-x
      ~a~x is well-formedsame as~x, but has typeICsame as~x
      c @= ac @= x is well-formedan lvalue referring tocsame asc @= x
      a @= bx @= y is well-formedan lvalue referring toasame asx @= y, except that the value that would be stored intox is stored intoa
      a @ bx @ y is well-formedsame asx @ y, but the result type is different:
      • Ifx @ y is of typeInt<IC>, the result has typeIC.
      • Ifx @ y is of typeInt<IL>, the result has typeIL.
      • Ifx @ y is of any other typeT, the result has typeT.
      same asx @ y
      b @ ay @ x is well-formedsame asy @ x, but the result type is different:
      • Ify @ x is of typeInt<IC>, the result has typeIC.
      • Ify @ x is of typeInt<IL>, the result has typeIL.
      • Ify @ x is of any other typeT, the result has typeT.
      same asy @ x

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3366
      (P2393R1)
      C++20the conversion between an integer-class type and its corresponding
      integer type was not guaranteed to produce a representable value
      guaranteed
      LWG 3376
      (P2393R1)
      C++20integer-class types could only be class typesalso allowed
      non-class types
      LWG 3467C++20bool was considered as an integer-like typeexcluded
      LWG 3575
      (P2393R1)
      C++20integer-class types were not guaranteed to be three-way-comparableguaranteed

      [edit]See also

      specifies that asemiregular type can be incremented with pre- and post-increment operators
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/is-integer-like&oldid=176026"

      [8]ページ先頭

      ©2009-2025 Movatter.jp