https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83389

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c++

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This isn't a libstdc++ bug. std::tie is doing exactly what it's meant to do,
which is generate a tuple of references, so of course it's not the same as
comparing the original objects (because in the general case the references
aren't all bound to members of the same object).

Reduced:

struct data { int x, y; char c1, c2; };

struct tuple { const int &x, &y; const char &c1, &c2; };

bool operator==(const tuple& l, const tuple& r) {
  return l.x == r.x && l.y == r.y && l.c1 == r.c1 && l.c2 == r.c2;
}

bool operator==(const data& l, const data& r) {
  return l.x == r.x && l.y == r.y && l.c1 == r.c1 && l.c2 == r.c2;
}

bool compare(const data& l, const data& r) {
  return tuple{l.x, l.y, l.c1, l.c2} == tuple{r.x, r.y, r.c1, r.c2};
}

int main()
{
    data d1{1,2,'a','b'};
    data d2{1,2,'a','d'};

    return (compare(d1,d2) ? 0 : -1);
}

Reply via email to