Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator==,<=>(std::inplace_vector)

      From cppreference.com
      <cpp‎ |container‎ |inplace vector
       
       
       
      std::inplace_vector
      Member types
      Member functions
      Non-member functions
      operator==operator<=>

       
      constexprfriendbool operator==(conststd::inplace_vector<T, N>& lhs,
                                       conststd::inplace_vector<T, N>& rhs);
      (1)(since C++26)
      constexprfriend synth-three-way-result<T>

          operator<=>(conststd::inplace_vector<T, N>& lhs,

                       conststd::inplace_vector<T, N>& rhs);
      (2)(since C++26)

      Compares the contents of twostd::inplace_vectors.

      1) 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.
      2) Compares the contents oflhs andrhs lexicographically. The comparison is performed as if by calling
      std::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 <T>).
      At least one of the following conditions must be satisfied:
      • T modelsthree_way_comparable.
      • < is defined for values of type (possibly const-qualified)T, and< is a total ordering relationship.
         Otherwise, the behavior is undefined.

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

      Contents

      [edit]Parameters

      lhs, rhs -std::inplace_vectors whose contents to compare
      -
      T must meet the requirements ofEqualityComparable in order to use overloads (1).

      [edit]Return value

      1)true if the contents of thestd::inplace_vectors are equal,false otherwise.
      2) The relative order of the first pair of non-equivalent elements inlhs andrhs if there are such elements,lhs.size()<=> rhs.size() otherwise.

      [edit]Complexity

      1) Constant iflhs andrhs are of different size, otherwise linear in the size of thestd::inplace_vector.
      2) Linear in the size of thestd::inplace_vector.

      [edit]Notes

      The relational operators are defined in terms ofsynth-three-way, which usesoperator<=> if possible, oroperator< otherwise.

      Notably, if the element does not itself provideoperator<=>, but is implicitly convertible to a three-way comparable type, that conversion will be used instead ofoperator<.

      [edit]Example

      Run this code
      #include <inplace_vector> int main(){constexprstd::inplace_vector<int,4>        a{1,2,3},        b{1,2,3},        c{7,8,9,10};     static_assert("""Compare equal containers:"&&(a!= b)==false&&(a== b)==true&&(a< b)==false&&(a<= b)==true&&(a> b)==false&&(a>= b)==true&&(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)<0&&(a<=> c)!=0&&(a<=> c)<=0&&"");}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/inplace_vector/operator_cmp&oldid=175563"

      [8]ページ先頭

      ©2009-2026 Movatter.jp