Просмотр исходного кода

Switch remaining relational operator overloads to spaceship. (#3668)

This doesn't matter too much as these were expanded by the LLVM iterator
facade, but eventually this should enable that facade to be a little
less fancy and should also simplify the dispatch to directly use the
three-way comparison.

One case is a bit subtle and didn't have a comment so I added one to
explain a bit what is going on there.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Chandler Carruth 2 лет назад
Родитель
Сommit
5e88fe72c9
2 измененных файлов с 9 добавлено и 4 удалено
  1. 3 2
      toolchain/lex/tokenized_buffer.h
  2. 6 2
      toolchain/parse/tree.h

+ 3 - 2
toolchain/lex/tokenized_buffer.h

@@ -5,6 +5,7 @@
 #ifndef CARBON_TOOLCHAIN_LEX_TOKENIZED_BUFFER_H_
 #define CARBON_TOOLCHAIN_LEX_TOKENIZED_BUFFER_H_
 
+#include <compare>
 #include <cstdint>
 #include <iterator>
 
@@ -81,8 +82,8 @@ class TokenIterator
   auto operator==(const TokenIterator& rhs) const -> bool {
     return token_ == rhs.token_;
   }
-  auto operator<(const TokenIterator& rhs) const -> bool {
-    return token_ < rhs.token_;
+  auto operator<=>(const TokenIterator& rhs) const -> std::strong_ordering {
+    return token_ <=> rhs.token_;
   }
 
   auto operator*() const -> const TokenIndex& { return token_; }

+ 6 - 2
toolchain/parse/tree.h

@@ -355,8 +355,12 @@ class Tree::PostorderIterator
   auto operator==(const PostorderIterator& rhs) const -> bool {
     return node_ == rhs.node_;
   }
-  auto operator<(const PostorderIterator& rhs) const -> bool {
-    return node_.index < rhs.node_.index;
+  // While we don't want users to directly leverage the index of `NodeId` for
+  // ordering, when we're explicitly walking in postorder, that becomes
+  // reasonable so add the ordering here and reach down for the index
+  // explicitly.
+  auto operator<=>(const PostorderIterator& rhs) const -> std::strong_ordering {
+    return node_.index <=> rhs.node_.index;
   }
 
   auto operator*() const -> NodeId { return node_; }