Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Comparison operators

      From cppreference.com
      <cpp‎ |language
       
       
      C++ language
      General topics
      Flow control
      Conditional execution statements
      Iteration statements (loops)
      Jump statements
      Functions
      Function declaration
      Lambda function expression
      inline specifier
      Dynamic exception specifications(until C++17*)
      noexcept specifier(C++11)
      Exceptions
      Namespaces
      Types
      Specifiers
      constexpr(C++11)
      consteval(C++20)
      constinit(C++20)
      Storage duration specifiers
      Initialization
      Expressions
      Alternative representations
      Literals
      Boolean -Integer -Floating-point
      Character -String -nullptr(C++11)
      User-defined(C++11)
      Utilities
      Attributes(C++11)
      Types
      typedef declaration
      Type alias declaration(C++11)
      Casts
      Memory allocation
      Classes
      Class-specific function properties
      Special member functions
      Templates
      Miscellaneous
       
      Expressions
      General
      Literals
      Operators
      Conversions
       

      Compares the arguments.

      Operator name Syntax OverloadablePrototype examples (forclass T)
      Inside class definitionOutside class definition
      Equal toa == bYesbool T::operator==(const U& b)const;bool operator==(const T& a,const U& b);
      Not equal toa != bYesbool T::operator!=(const U& b)const;bool operator!=(const T& a,const U& b);
      Less thana < bYesbool T::operator<(const U& b)const;bool operator<(const T& a,const U& b);
      Greater thana > bYesbool T::operator>(const U& b)const;bool operator>(const T& a,const U& b);
      Less than or equal toa <= bYesbool T::operator<=(const U& b)const;bool operator<=(const T& a,const U& b);
      Greater than or equal toa >= bYesbool T::operator>=(const U& b)const;bool operator>=(const T& a,const U& b);
      Three-way comparison(C++20)a <=> bYesT::operator<=>(const U& b)const;[1]operator<=>(const T& a,const U& b);[1]
      Notes
      • Where built-in operators returnbool, mostuser-defined overloads also returnbool so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (includingvoid).
      • U can be any type includingT.
      1. 1.01.1R is the return type ofoperator<=> (see below)

      Contents

      [edit]Two-way comparison

      The two-way comparison operator expressions have the form

      [edit]Relational operators
      lhs<rhs (1)
      lhs>rhs (2)
      lhs<=rhs (3)
      lhs>=rhs (4)
      [edit]Equality operators
      lhs==rhs (5)
      lhs!=rhs (6)
      1) Returnstrue iflhs is less thanrhs,false otherwise.
      2) Returnstrue iflhs is greater thanrhs,false otherwise.
      3) Returnstrue iflhs is less than or equal torhs,false otherwise.
      4) Returnstrue iflhs is greater than or equal torhs,false otherwise.
      5) Returnstrue iflhs is equal torhs,false otherwise.
      6) Returnstrue iflhs is not equal torhs,false otherwise.

      [edit]Built-in two-way comparison operators

      For built-in two-way comparison operators,lvalue-to-rvalue conversions,array-to-pointer conversions(until C++26) andfunction-to-pointer conversions are applied tolhs andrhs .

      The comparison is deprecated if bothlhs andrhs have array type prior to the application of these conversions.

      (since C++20)
      (until C++26)

      For built-in relational operators, if one of the operands is a pointer, thearray-to-pointer conversion is performed on the other operand.

      For built-in equality operators, if one of the operands is a pointer or anull pointer constant, the array-to-pointer conversion is performed on the other operand.

      (since C++26)

      For built-in two-way comparison operators, the result is abool prvalue.

      [edit]Built-in arithmetic comparison

      If the converted operands both have arithmetic or enumeration type (scoped or unscoped),usual arithmetic conversions are performed on both operands. The values are compared after conversions:

      Run this code
      #include <iostream> int main(){    static_assert(sizeof(unsignedchar)< sizeof(int),"Cannot compare signed and smaller unsigned properly");int a=-1;int b=1;unsignedint c=1;unsignedchar d=1; std::cout<<std::boolalpha<<"Comparing two signed values:\n"" -1 == 1 ? "<<(a== b)<<"\n"" -1 <  1 ? "<<(a<  b)<<"\n"" -1 >  1 ? "<<(a>  b)<<"\n""Comparing signed and unsigned:\n"// may issue different-signedness warning:" -1 == 1 ? "<<(a== c)<<"\n"// may issue different-signedness warning:" -1 <  1 ? "<<(a<  c)<<"\n"// may issue different-signedness warning:" -1 >  1 ? "<<(a>  c)<<"\n""Comparing signed and smaller unsigned:\n"" -1 == 1 ? "<<(a== d)<<"\n"" -1 <  1 ? "<<(a<  d)<<"\n"" -1 >  1 ? "<<(a>  d)<<'\n';}

      Output:

      Comparing two signed values: -1 == 1 ? false -1 <  1 ? true -1 >  1 ? falseComparing signed and unsigned: -1 == 1 ? false -1 <  1 ? false -1 >  1 ? trueComparing signed and smaller unsigned: -1 == 1 ? false -1 <  1 ? true -1 >  1 ? false

      [edit]Built-in pointer equality comparison

      The converted operands of equality operators== and!= can also have the typestd::nullptr_t,(since C++11) pointer type or pointer-to-member type.

      Built-in pointer equality comparison has three possible results: equal, unequal and unspecified. The values yielded by equality operators for built-in pointer equality comparison is listed below:

       Comparison result 
      ofp andq
      Value yielded by
      p== qp!= q
      equaltruefalse
      unequalfalsetrue
      unspecified unspecifiedbool value 

      If at least one of convertedlhs andrhs is a pointer,pointer conversions,function pointer conversions(since C++17) andqualification conversions are performed on both converted operands to bring them to theircomposite pointer type. The two pointers of the composite pointer type are compared as follows:

      • represents the address past the end of a different complete non-array object, or
      • represents the address one past the last element of a different complete array object,
      the result of the comparison is unspecified.
      • Otherwise, if the pointers are both null, both point to the same function, or both represent the same address (i.e., they point to or are past the end of the same object), they compare equal.
      • Otherwise, the pointers compare unequal.

      If at least one of convertedlhs andrhs is a pointer to member,pointer-to-member conversions,function pointer conversions(since C++17) andqualification conversions are performed on both converted operands to bring them to theircomposite pointer type. The two pointers to members of the composite pointer type are compared as follows:

      • If two pointers to members are both the null member pointer value, they compare equal.
      • If only one of two pointers to members is the null member pointer value, they compare unequal.
      • If either is a pointer to avirtual member function, the result is unspecified.
      • If one refers to a member of classC1 and the other refers to a member of a different classC2, where neither is a base class of the other, the result is unspecified.
      • If both refer to (possibly different) members of the sameunion, they compare equal.
      • Otherwise, two pointers to members compare equal if they would refer to the same member of the samemost derived object or the same subobject if indirection with a hypothetical object of the associated class type were performed, otherwise they compare unequal.
      struct P{};struct Q: P{int x;};struct R: P{int x;}; int P::*bx=(int(P::*))&Q::x;int P::*cx=(int(P::*))&R::x; bool b1=(bx== cx);// unspecified struct B{int f();};struct L: B{};struct R: B{};struct D: L, R{}; int(B::*pb)()=&B::f;int(L::*pl)()= pb;int(R::*pr)()= pb;int(D::*pdl)()= pl;int(D::*pdr)()= pr; bool x=(pdl== pdr);// falsebool y=(pb== pl);// true

      Two operands of typestd::nullptr_t or one operand of typestd::nullptr_t and the other a null pointer constant compare equal.

      (since C++11)

      [edit]Built-in pointer relational comparison

      The converted operands of relational operators>,<,>= and<= can also have pointer type.

      Built-in pointer relational comparison on unequal pointersp andq has three possible results:p is greater,q is greater and unspecified. The values yielded by relational operators for built-in pointer relational comparison is listed below:

       Comparison result 
      ofp andq
      Value yielded by
       p> q  p< q  p>= q  p<= q 
      equalfalsefalsetruetrue
      p is greatertruefalsetruefalse
      q is greaterfalsetruefalsetrue
      unspecifiedunspecifiedbool value

      If convertedlhs andrhs are both pointers,pointer conversions,function pointer conversions(since C++17) andqualification conversions are performed on both converted operands to bring them to theircomposite pointer type. The two pointers of the composite pointer type are compared as follows:

      • If the pointers compare equal or the equality comparison result is unspecified, the relational comparison result falls into the same category.
      • Otherwise (the pointers compare unequal), if any of the pointers is not a pointer to object, the result is unspecified.
      • Otherwise (both pointers point to objects), the result is defined in terms of a partial order consistent with the following rules:
      • Given two different elementshigh andlow of an array such thanhigh has higher subscript thanlow, if one pointer points tohigh (or a subobject ofhigh) and the other pointer points tolow (or a subobject oflow), the former compares greater than the latter.
      • If one pointer points to an elementelem (or to a subobject ofelem) of an array, and the other pointer is past the end of the same array, the past-the-end pointer compares greater than the other pointer.
      • If one pointer points to a complete object, a base class subobject or a member subobjectobj (or to a subobject ofobj), and the other pointer is past the end ofobj, the past-the-end pointer compares greater than the other pointer.

      • If the pointers point to differentnon-zero-sized(since C++20) non-static data members with the samemember access(until C++23) of the same object of a non-union class type, or to subobjects of such members, recursively, the pointer to the later declared member compares greater than the other pointer.
      • Otherwise, the result is unspecified.

      [edit]Pointer total order

      There exists animplementation-defined strict total order over pointers in each program. The strict total order is consistent with the partial order described above: unspecified results become implementation-defined, while other results stay the same.

      Pointer comparison with the strict total order is applied in the following cases:

      (since C++14)
      (since C++20)

      [edit]Overloads

      Inoverload resolution against user-defined operators, for every pair of promoted arithmetic typesL andR, including enumeration types, the following function signatures participate in overload resolution:

      bool operator<(L, R);
      bool operator>(L, R);
      bool operator<=(L, R);
      bool operator>=(L, R);
      bool operator==(L, R);
      bool operator!=(L, R);

      For every typeP which is either pointer to object or pointer to function, the following function signatures participate in overload resolution:

      bool operator<(P, P);
      bool operator>(P, P);
      bool operator<=(P, P);
      bool operator>=(P, P);
      bool operator==(P, P);
      bool operator!=(P, P);

      For every typeMP that is a pointer to member object or pointer to member function orstd::nullptr_t(since C++11), the following function signatures participate in overload resolution:

      bool operator==(MP, MP);
      bool operator!=(MP, MP);
      Run this code
      #include <iostream> struct Foo{int n1;int n2;}; union Union{int n;double d;}; int main(){std::cout<<std::boolalpha; char a[4]="abc";char* p1=&a[1];char* p2=&a[2];std::cout<<"Pointers to array elements:\n"<<"p1 == p2? "<<(p1== p2)<<'\n'<<"p1 <  p2? "<<(p1<  p2)<<'\n';     Foo f;int* p3=&f.n1;int* p4=&f.n2;std::cout<<"Pointers to members of a class:\n"<<"p3 == p4? "<<(p3== p4)<<'\n'<<"p3 <  p4? "<<(p3<  p4)<<'\n';     Union u;int* p5=&u.n;double* p6=&u.d;std::cout<<"Pointers to members of a union:\n"<<"p5 == (void*)p6? "<<(p5==(void*)p6)<<'\n'<<"p5 <  (void*)p6? "<<(p5<(void*)p6)<<'\n';}

      Output:

      Pointers to array elements:p1 == p2? falsep1 <  p2? truePointers to members of a class:p3 == p4? falsep3 <  p4? truePointers to members of a union:p5 == (void*)p6? truep5 <  (void*)p6? false

      Three-way comparison

      The three-way comparison operator expressions have the form

      a<=>b

      The expression returns an object such that

      • (a<=> b)<0 ifa< b,
      • (a<=> b)>0 ifa> b,
      • (a<=> b)==0 ifa andb are equal/equivalent.

      If one of the operands is of typebool and the other is not, the program is ill-formed.

      If both operands have arithmetic types, or if one operand has unscoped enumeration type and the other has integral type, the usual arithmetic conversions are applied to the operands, and then

      • If a narrowing conversion is required, other than from an integral type to a floating point type, the program is ill-formed.
      • Otherwise, if the operands have integral type, the operator yields a prvalue of typestd::strong_ordering:
      • std::strong_ordering::equal if both operands are arithmetically equal,
      • std::strong_ordering::less if the first operand is arithmetically less than the second,
      • std::strong_ordering::greater otherwise.
      • Otherwise, the operands have floating-point type, and the operator yields a prvalue of typestd::partial_ordering. The expressiona<=> b yields
      • std::partial_ordering::less ifa is less thanb,
      • std::partial_ordering::greater ifa is greater thanb,
      • std::partial_ordering::equivalent ifa is equivalent tob (-0<=>+0 is equivalent),
      • std::partial_ordering::unordered (NaN<=> anything is unordered).

      If both operands have the same enumeration typeE, the operator yields the result of converting the operands to the underlying type of E and applying<=> to the converted operands.

      If at least one of the operands is a pointer to object or pointer to member,array-to-pointer conversions,pointer conversions andqualification conversions are applied to both operands to bring them to theircomposite pointer type.

      For converted pointer operandsp andq,p<=> q returns a prvalue of typestd::strong_ordering:

      • std::strong_ordering::equal if theycompare equal,
      • std::strong_ordering::less ifqcompares greater thanp,
      • std::strong_ordering::greater ifp compares greater thanq,
      • unspecified result if the two-way comparison result is unspecified.

      Otherwise, the program is ill-formed.

      Overloads

      Inoverload resolution against user-defined operators, for pointer or enumeration typeT, the following function signature participates in overload resolution:

      R operator<=>(T, T);

      WhereR is the ordering category type defined above.

      Run this code
      #include <compare>#include <iostream> int main(){double foo=-0.0;double bar=0.0; auto res= foo<=> bar; if(res<0)std::cout<<"-0 is less than 0";elseif(res>0)std::cout<<"-0 is greater than 0";elseif(res==0)std::cout<<"-0 and 0 are equal";elsestd::cout<<"-0 and 0 are unordered";}

      Output:

      -0 and 0 are equal
      (since C++20)

      [edit]Notes

      Because comparison operators group left-to-right, the expressiona< b< c is parsed(a< b)< c, and nota<(b< c) or(a< b)&&(b< c).

      Run this code
      #include <iostream> int main(){int a=3, b=2, c=1; std::cout<<std::boolalpha<<(a< b< c)<<'\n'// true; maybe warning<<((a< b)< c)<<'\n'// true<<(a<(b< c))<<'\n'// false<<((a< b)&&(b< c))<<'\n';// false}

      A common requirement foruser-defined operator< isstrict weak ordering. In particular, this is required by the standard algorithms and containers that work withCompare types:std::sort,std::max_element,std::map, etc.

      Thecomparison result of pointers to different non-static data members of the same class implies that non-static data members in each of the threemember access modes(until C++23) are positioned in memory in order of declaration.

      Although the results of comparing pointers of random origin (e.g. not all pointing to members of the same array) is unspecified, many implementations providestrict total ordering of pointers, e.g. if they are implemented as addresses within continuous virtual address space. Those implementations that do not (e.g. where not all bits of the pointer are part of a memory address and have to be ignored for comparison, or an additional calculation is required or otherwise pointer and integer is not a 1 to 1 relationship), provide a specialization ofstd::less for pointers that has that guarantee. This makes it possible to use all pointers of random origin as keys in standard associative containers such asstd::set orstd::map.

      For the types that are bothEqualityComparable andLessThanComparable, the C++ standard library makes a distinction betweenequality, which is the value of the expressiona== b andequivalence, which is the value of the expression!(a< b)&&!(b< a).

      Comparison between pointers and null pointer constants was removed by the resolution ofCWG issue 583 included inN3624:

      Run this code
      void f(char* p){if(p>0){/*...*/}// Error with N3624, compiled before N3624if(p> nullptr){/*...*/}// Error with N3624, compiled before N3624} int main(){}

      Three-way comparison can be automatically generated for class types, seedefault comparisons.

      If both of the operands are arrays, three-way comparison is ill-formed.

      unsignedint i=1;auto r=-1< i;// existing pitfall: returns ‘false’auto r2=-1<=> i;// Error: narrowing conversion required
      Feature-test macroValueStdFeature
      __cpp_impl_three_way_comparison201907L(C++20)Three-way comparison (compiler support)
      __cpp_lib_three_way_comparison201907L(C++20)Three-way comparison (library support); adding three-way comparison to the library

      [edit]Standard library

      Comparison operators are overloaded for many classes in the standard library.

      (removed in C++20)
      checks whether the objects refer to the same type
      (public member function ofstd::type_info)[edit]
      (removed in C++20)(removed in C++20)(C++20)
      compares twoerror_codes
      (function)[edit]
      (removed in C++20)(removed in C++20)(C++20)
      compareserror_conditions anderror_codes
      (function)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values in thepair
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values in the tuple
      (function template)[edit]
      (removed in C++20)
      compares the contents
      (public member function ofstd::bitset<N>)[edit]
      (removed in C++20)
      compares two allocator instances
      (public member function ofstd::allocator<T>)[edit]
      compares to anotherunique_ptr or withnullptr
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      compares with anothershared_ptr or withnullptr
      (function template)[edit]
      (removed in C++20)
      compares astd::function withnullptr
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)(C++11)(C++11)(C++11)(C++11)(C++20)
      compares two durations
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)(C++11)(C++11)(C++11)(C++11)(C++20)
      compares two time points
      (function template)[edit]
      (removed in C++20)
      compares twoscoped_allocator_adaptor objects
      (function template)[edit]
      compares the underlyingstd::type_index objects
      (public member function ofstd::type_index)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares two strings
      (function template)[edit]
      (removed in C++20)
      equality comparison between locale objects
      (public member function ofstd::locale)[edit]
      (C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20)
      lexicographically compares the values of twoarrays
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twodeques
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20)
      lexicographically compares the values of twoforward_lists
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twolists
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twovectors
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twomaps
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twomultimaps
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twosets
      (function template)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      lexicographically compares the values of twomultisets
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)
      compares the values in the unordered_map
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)
      compares the values in the unordered_multimap
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)
      compares the values in the unordered_set
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)
      compares the values in the unordered_multiset
      (function template)[edit]
      lexicographically compares the values of twoqueues
      (function template)[edit]
      lexicographically compares the values of twostacks
      (function template)[edit]
      compares the underlying iterators
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)(C++11)(C++11)(C++11)(C++11)(C++20)
      compares the underlying iterators
      (function template)[edit]
      (removed in C++20)
      compares twoistream_iterators
      (function template)[edit]
      (removed in C++20)
      compares twoistreambuf_iterators
      (function template)[edit]
      (removed in C++20)
      compares two complex numbers or a complex and a scalar
      (function template)[edit]
      compares two valarrays or a valarray with a value
      (function template)[edit]
      (C++11)(C++11)(removed in C++20)
      compares the internal states of two pseudo-random number engines
      (function)[edit]
      (C++11)(C++11)(removed in C++20)
      compares two distribution objects
      (function)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      compares asub_match with anothersub_match, a string, or a character
      (function template)[edit]
      (removed in C++20)
      lexicographically compares the values in the two match result
      (function template)[edit]
      (removed in C++20)
      compares tworegex_iterators
      (public member function ofstd::regex_iterator<BidirIt,CharT,Traits>)[edit]
      (removed in C++20)
      compares tworegex_token_iterators
      (public member function ofstd::regex_token_iterator<BidirIt,CharT,Traits>)[edit]
      (removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
      compares twothread::id objects
      (function)[edit]

      The namespacestd::rel_ops provides generic operators!=,>,<=, and>=:

      Defined in header<utility>
      Defined in namespacestd::rel_ops
      automatically generates comparison operators based on user-definedoperator== andoperator<
      (function template)[edit]

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      CWG 583
      (N3624)
      C++98all six comparison operators could be used to
      compare a pointer with a null pointer constant
      only equality operators
      are allowed
      CWG 661C++98the actual semantics of arithmetic comparisons (e.g.
      whether1<2 yieldstrue orfalse) were unspecified
      specification added
      CWG 879C++98pointers to function types and pointers
      tovoid did not have built-in comparisons
      added comparison
      specification for these pointers
      CWG 1596C++98non-array objects were considered to belong to arrays with
      one element only for the purpose of pointer arithmetic
      the rule is also
      applied to comparison
      CWG 1598C++98two pointers to members of classes that are different and
      neither is the base class of the other did not compare equal
      even if the offsets of the pointed members can be the same
      the result is
      unspecified
      in this case
      CWG 1858C++98it was not clear whether two pointers to members
      that refer to different members of the same union
      compare equal as if they refer to the same member
      they compare
      equal in this case
      CWG 2419C++98a pointer to non-array object was only treated as a
      pointer to the first element of an array with size 1
      in pointer comparison if the pointer is obtained by&
      applies to all pointers
      to non-array objects
      CWG 2526C++98the definition of relational comparison (>,>=,< and<=) of
      pointers tovoid and function pointers were removed byN3624
      restored
      CWG 2796C++17function pointer conversions were not performed on the converted
      pointer operands during built-in pointer relational comparisons
      performs these
      conversions in this case

      [edit]See also

      Common operators
      assignmentincrement
      decrement
      arithmeticlogicalcomparisonmember
      access
      other

      a= b
      a+= b
      a-= b
      a*= b
      a/= b
      a%= b
      a&= b
      a|= b
      a^= b
      a<<= b
      a>>= b

      ++a
      --a
      a++
      a--

      +a
      -a
      a+ b
      a- b
      a* b
      a/ b
      a% b
      ~a
      a& b
      a| b
      a^ b
      a<< b
      a>> b

      !a
      a&& b
      a|| b

      a== b
      a!= b
      a< b
      a> b
      a<= b
      a>= b
      a<=> b

      a[...]
      *a
      &a
      a->b
      a.b
      a->*b
      a.*b

      function call

      a(...)
      comma

      a, b
      conditional

      a? b: c
      Special operators

      static_cast converts one type to another related type
      dynamic_cast converts within inheritance hierarchies
      const_cast adds or removescv-qualifiers
      reinterpret_cast converts type to unrelated type
      C-style cast converts one type to another by a mix ofstatic_cast,const_cast, andreinterpret_cast
      new creates objects with dynamic storage duration
      delete destructs objects previously created by the new expression and releases obtained memory area
      sizeof queries the size of a type
      sizeof... queries the size of apack(since C++11)
      typeid queries the type information of a type
      noexcept checks if an expression can throw an exception(since C++11)
      alignof queries alignment requirements of a type(since C++11)

      C documentation forComparison operators
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/language/operator_comparison&oldid=177936"

      [8]ページ先頭

      ©2009-2025 Movatter.jp