How and why did the ISO C ++ Standards Committee (RG21) decide to accept the proposal for the spacecraft operator as is?

In a recently published paper [1] Herb Sutter et al. Describe the extension of the C ++ programming language by a three-way comparison operator. The authors cite a significant number of earlier proposals, all of which were ultimately rejected.

The clever concept of the core of the new approach is to encode various categories of relationships in the inverse type of comparison operator. The authors declare that

The main objective of the project is conceptual integrity [Brooks 1975], which means that the design is coherent and reliably does what the user expects him to do.

Only five categories of comparison relationships are introduced:

  • weak_equality
  • strong_equality
  • partial_ordering
  • weak_ordering
  • strong_ordering

, :

, , .

, weak_equality , strong_equality , weak_ordering - , strong_ordering - . [3] , , .

partial_ordering.

, partial_ordering , . , .

.

- . , -, , . , A B A A B B ⊆ A , A B ( ).

, ( ).

partial_ordering, NaNs, , -0 <=> +0 equivalent NaN <=> anything unordered.

, , , . ? , NaN undefined !

2.5. , :

  • strong_order()
  • weak_order()
  • partial_order()
  • strong_equal()
  • weak_equal()

, . ,

operator<

, , operator< . , weak_order() operator== operator<, , , .

.

[4], ISO ++ (21) ++ 20 2017 .

: ?

:

  • .
  • .
  • - .
  • , .
  • .
  • .

[1] Herb Sutter .: . ISO/IEC JTC1/SC22/WG21 P0515R2 ( ), 2017-09-30. URL https://wg21.link/p0515r2

[2] . : (). ISO/IEC JTC1/SC22/WG21 P0768R0 ( ), 2017-09-30. URL https://wg21.link/p0768r0

[3] Hewlett-Packard: . , 1994. URL https://www.sgi.com/tech/stl/StrictWeakOrdering.html

[4] : . C++ , 2017 . URL https://botondballo.wordpress.com/2017/11/20/trip-report-c-standards-meeting-in-albuquerque-november-2017/

[5] : . URL https://en.wikipedia.org/wiki/Indiana_Pi_Bill

, , : Alternative hierarchy of comparison relationships

2.5 :

template <class T>
std::linear_ordering linear_order(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T>
std::weak_ordering weak_order(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T>
std::partial_ordering partial_order(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T>
std::quasi_ordering quasi_order(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T>
std::equality equal(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T>
std::equivalence equivalent(const T& a, const T& b)
{
   return compare_3way(a, b);
}

template <class T, class U>
auto compare_3way(const T& a, const U& b)
{
   return a <=> b;
}

template <class T, class U>
auto compare_3way(const T& a, const U& b)
{
   if constexpr (/* can invoke a <=> b */)
   {
      return a <=> b;
   }
   else if constexpr (std::is_same_v<T, U> &&
      /* can invoke a.M <=> b.M for each member M of T */)
   {
      /* do that */
   }
}

template <class T, class U>
auto compare_3way(const T& a, const U& b)
{
   if constexpr (/* can invoke a <=> b */)
   {
      return a <=> b;
   }
   else if constexpr (std::is_same_v<T, U> &&
      /* can invoke compare_3way(a.M, b.M) for each member M of T */)
   {
      /* do that */
   }
}
+3

Source: https://habr.com/ru/post/1689820/


All Articles