[llvm] r268062 - Add operator- to Path's reverse_iterator. Needed for D19666

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 15:55:12 PDT 2016


Usually member variables that can be non-instance members should be
non-instance members so as to allow equal conversions on the left and right
hand operands. One way to do this is to declare it as a friend, instead of
as a non-static member (or even define it in terms of another operation)

Also not sure whether that operation should be out of line, or just make it
inline?

On Fri, Apr 29, 2016 at 9:48 AM, Filipe Cabecinhas via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: filcab
> Date: Fri Apr 29 11:48:07 2016
> New Revision: 268062
>
> URL: http://llvm.org/viewvc/llvm-project?rev=268062&view=rev
> Log:
> Add operator- to Path's reverse_iterator. Needed for D19666
>
> Reviewers: rafael, craig.topper, bogner
>
> Subscribers: llvm-commits
>
> Differential Revision: http://reviews.llvm.org/D19724
>
> Modified:
>     llvm/trunk/include/llvm/Support/Path.h
>     llvm/trunk/lib/Support/Path.cpp
>
> Modified: llvm/trunk/include/llvm/Support/Path.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Path.h?rev=268062&r1=268061&r2=268062&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/Path.h (original)
> +++ llvm/trunk/include/llvm/Support/Path.h Fri Apr 29 11:48:07 2016
> @@ -87,6 +87,9 @@ public:
>    reverse_iterator &operator++();    // preincrement
>    bool operator==(const reverse_iterator &RHS) const;
>    bool operator!=(const reverse_iterator &RHS) const { return !(*this ==
> RHS); }
> +
> +  /// @brief Difference in bytes between this and RHS.
> +  ptrdiff_t operator-(const reverse_iterator &RHS) const;
>  };
>
>  /// @brief Get begin iterator over \a path.
>
> Modified: llvm/trunk/lib/Support/Path.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=268062&r1=268061&r2=268062&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/Path.cpp (original)
> +++ llvm/trunk/lib/Support/Path.cpp Fri Apr 29 11:48:07 2016
> @@ -353,6 +353,10 @@ bool reverse_iterator::operator==(const
>           Position == RHS.Position;
>  }
>
> +ptrdiff_t reverse_iterator::operator-(const reverse_iterator &RHS) const {
> +  return Position - RHS.Position;
> +}
> +
>  StringRef root_path(StringRef path) {
>    const_iterator b = begin(path),
>                   pos = b,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160429/366e081f/attachment.html>


More information about the llvm-commits mailing list