Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator==,!=,<,<=,>,>=,<=>(std::multimap)

      From cppreference.com
      <cpp‎ |container‎ |multimap

      [edit template]
       
       
       
      std::multimap
      Member functions
      Non-member functions
      operator==operator<=>
      (C++20)

      operator!=operator<operator>operator<=operator>=
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
      Deduction guides(C++17)
       
      Defined in header<map>
      template<class Key,class T,class Compare,class Alloc>

      bool operator==(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (1)(constexpr since C++26)
      template<class Key,class T,class Compare,class Alloc>

      bool operator!=(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (2)(until C++20)
      template<class Key,class T,class Compare,class Alloc>

      bool operator<(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (3)(until C++20)
      template<class Key,class T,class Compare,class Alloc>

      bool operator<=(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (4)(until C++20)
      template<class Key,class T,class Compare,class Alloc>

      bool operator>(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (5)(until C++20)
      template<class Key,class T,class Compare,class Alloc>

      bool operator>=(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (6)(until C++20)
      template<class Key,class T,class Compare,class Alloc>

      /* see below */
          operator<=>(conststd::multimap<Key, T, Compare, Alloc>& lhs,

                       conststd::multimap<Key, T, Compare, Alloc>& rhs);
      (7)(since C++20)
      (constexpr since C++26)

      Compares the contents of twomultimaps.

      Letvalue_type be the value type ofmultimap (i.e.,typename multimap::value_type):

      1,2) Checks if the contents oflhs andrhs are equal, that is, they have the same number of elements and each element inlhs compares equal with the element inrhs at the same position.
      Equivalent to:

      returnstd::distance(lhs.begin(), lhs.end())
                     ==std::distance(rhs.begin(), rhs.end())
                 &&std::equal(lhs.begin(), lhs.end(), rhs.begin());

      (until C++14)

      returnstd::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());

      (since C++14)
      Ifvalue_type is notEqualityComparable, the behavior is undefined.
      3-7) Compares the contents oflhs andrhs lexicographically.
      3-6) Equivalent toreturnstd::lexicographical_compare(lhs.begin(), lhs.end(),
                                          rhs.begin(), rhs.end());
      .
      If any of the following conditions is satisfied, the behavior is undefined:
      7) Equivalent toreturnstd::lexicographical_compare_three_way(lhs.begin(), lhs.end(),
                                                    rhs.begin(), rhs.end(),
                                                    synth-three-way)
      .
      The return type is the return type ofsynth-three-way (i.e.,synth-three-way-result <value_type>).
      If any of the following conditions is satisfied, the behavior is undefined:
      • T does not modelthree_way_comparable.
      • operator< is not defined for values of type (possibly const-qualified)value_type.
      • operator< does not establishtotal order.

      The<,<=,>,>=, and!= operators aresynthesized fromoperator<=> andoperator== respectively.

      (since C++20)

      Contents

      [edit]Parameters

      lhs, rhs -multimaps whose contents to compare

      [edit]Return value

      Operatorlhs andrhs
      are equal
      lhs is
       lexicographically greater 
      rhs is
       lexicographically greater 
      operator==truefalse
      operator!=falsetrue
      operator<falsefalsetrue
      operator<=true
      operator>falsetruefalse
      operator>=true
       operator<=>  a value equal to0 a value greater then0a value less than0

      [edit]Complexity

      1,2) Constant iflhs andrhs are of different size, otherwise linear in the size of themultimap.
      3-7) Linear in the size of themultimap.

      [edit]Notes

      The relational operators are defined in terms ofvalue_type'soperator<.

      (until C++20)

      The relational operators are not defined. The rewritten candidateoperator<=> will be selected by overload resolution.

      operator<=> usesvalue_type'soperator<=> if possible, orvalue_type'soperator< otherwise. Notably, if thevalue_type does not itself provideoperator<=>, but is implicitly convertible to a three-way comparable type, that conversion will be used instead ofoperator<.

      (since C++20)

      These non-member comparison operators do not useCompare to compare elements.

      [edit]Example

      Run this code
      #include <cassert>#include <compare>#include <map> int main(){std::multimap<int,char> a{{1,'a'},{2,'b'},{3,'c'}};std::multimap<int,char> b{{1,'a'},{2,'b'},{3,'c'}};std::multimap<int,char> c{{7,'Z'},{8,'Y'},{9,'X'},{10,'W'}}; assert("""Compare equal containers:"&&(a!= b)==false&&(a== b)==true&&(a< b)==false&&(a<= b)==true&&(a> b)==false&&(a>= b)==true&&(a<=> b)!= std::weak_ordering::less&&(a<=> b)!= std::weak_ordering::greater&&(a<=> b)== std::weak_ordering::equivalent&&(a<=> b)>=0&&(a<=> b)<=0&&(a<=> b)==0&& "Compare non equal containers:"&&(a!= c)==true&&(a== c)==false&&(a< c)==true&&(a<= c)==true&&(a> c)==false&&(a>= c)==false&&(a<=> c)== std::weak_ordering::less&&(a<=> c)!= std::weak_ordering::equivalent&&(a<=> c)!= std::weak_ordering::greater&&(a<=> c)<0&&(a<=> c)!=0&&(a<=> c)<=0&&"");}

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3431C++20operator<=> did not requireT
      to modelthree_way_comparable
      requires
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/multimap/operator_cmp&oldid=161962"

      [8]ページ先頭

      ©2009-2025 Movatter.jp