[all-commits] [llvm/llvm-project] 411885: [libc++] NFCI: Restore code duplication in wrap_it...

Quuxplusone via All-commits all-commits at lists.llvm.org
Wed Jul 14 17:11:51 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4118858b4e4d072ac2ceef6cbc52088438781f39
      https://github.com/llvm/llvm-project/commit/4118858b4e4d072ac2ceef6cbc52088438781f39
  Author: Arthur O'Dwyer <arthur.j.odwyer at gmail.com>
  Date:   2021-07-14 (Wed, 14 Jul 2021)

  Changed paths:
    M libcxx/include/__iterator/wrap_iter.h
    A libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp

  Log Message:
  -----------
  [libc++] NFCI: Restore code duplication in wrap_iter, with test.

It turns out that D105040 broke `std::rel_ops`; we actually do need
both a one-template-parameter and a two-template-parameter version of
all the comparison operators, because if we have only the heterogeneous
two-parameter version, then `x > x` is ambiguous:

    template<class T, class U> int f(S<T>, S<U>) { return 1; }
    template<class T> int f(T, T) { return 2; }  // rel_ops
    S<int> s; f(s,s);  // ambiguous between #1 and #2

Adding the one-template-parameter version fixes the ambiguity:

    template<class T, class U> int f(S<T>, S<U>) { return 1; }
    template<class T> int f(T, T) { return 2; }  // rel_ops
    template<class T> int f(S<T>, S<T>) { return 3; }
    S<int> s; f(s,s);  // #3 beats both #1 and #2

We have the same problem with `reverse_iterator` as with `__wrap_iter`.
But so do libstdc++ and Microsoft, so we're not going to worry about it.

Differential Revision: https://reviews.llvm.org/D105894




More information about the All-commits mailing list