Skip to content

Commit

Permalink
[C++17] Merge upsteam change for Don't use std::iterator in PATH.h (#…
Browse files Browse the repository at this point in the history
…5483)

Merge upstream change

llvm/llvm-project@91c8daf

In converting this over to iterator_facade_base, some member
operators and methods are no longer needed since iterator_facade
implements them in the base class using CRTP.

This is part of enable C++17.
  • Loading branch information
python3kgae authored Aug 2, 2023
1 parent 212a2bf commit a5b0488
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions include/llvm/Support/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/DataTypes.h"
#include <iterator>

Expand Down Expand Up @@ -48,7 +49,8 @@ namespace path {
/// C:\foo\bar => C:,/,foo,bar
/// @endcode
class const_iterator
: public std::iterator<std::input_iterator_tag, const StringRef> {
: public iterator_facade_base<const_iterator, std::input_iterator_tag,
const StringRef> {
StringRef Path; ///< The entire path.
StringRef Component; ///< The current component. Not necessarily in Path.
size_t Position; ///< The iterators current position within Path.
Expand All @@ -59,11 +61,9 @@ class const_iterator

public:
reference operator*() const { return Component; }
pointer operator->() const { return &Component; }
const_iterator &operator++(); // preincrement
const_iterator &operator++(int); // postincrement
bool operator==(const const_iterator &RHS) const;
bool operator!=(const const_iterator &RHS) const { return !(*this == RHS); }

/// @brief Difference in bytes between this and RHS.
ptrdiff_t operator-(const const_iterator &RHS) const;
Expand All @@ -75,7 +75,8 @@ class const_iterator
/// \a path in reverse order. The traversal order is exactly reversed from that
/// of \a const_iterator
class reverse_iterator
: public std::iterator<std::input_iterator_tag, const StringRef> {
: public iterator_facade_base<reverse_iterator, std::input_iterator_tag,
const StringRef> {
StringRef Path; ///< The entire path.
StringRef Component; ///< The current component. Not necessarily in Path.
size_t Position; ///< The iterators current position within Path.
Expand All @@ -85,11 +86,9 @@ class reverse_iterator

public:
reference operator*() const { return Component; }
pointer operator->() const { return &Component; }
reverse_iterator &operator++(); // preincrement
reverse_iterator &operator++(int); // postincrement
bool operator==(const reverse_iterator &RHS) const;
bool operator!=(const reverse_iterator &RHS) const { return !(*this == RHS); }
};

/// @brief Get begin iterator over \a path.
Expand Down

0 comments on commit a5b0488

Please sign in to comment.