10

According to Link, with regards to std::tuple...

libstdc++ always places the members in reverse order, and libc++ always places the members in the order given

Assuming that's true, is there a reason (historical or otherwise) why libstdc++ uses reverse order?

Bonus: Has either implementation ever changed its std::tuple ordering for any reason?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Ixrec
  • 966
  • 1
  • 7
  • 20
  • 1
    I'm not aware of either library breaking its ABI, and reversing that order would absolutely break the ABI. – MSalters Dec 27 '14 at 01:39
  • It hadn't even occurred to me that changing the order would break the ABI, but now it seems obvious. I guess that answers that part of the question. Thanks. – Ixrec Dec 27 '14 at 22:55
  • I made a change to the libstdc++ `tuple` layout yesterday (see [PR 56785](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56785)) but only to remove some empty base classes and make it more compact. The ordering of elements didn't change. – Jonathan Wakely Jan 17 '15 at 18:34

1 Answers1

12

See this answer for why libc++ chose forward order. As for why libstdc++ chose reverse order, that is probably because that's how it was demonstrated in the variadics template proposal, and is the more obvious implementation.

Bonus: No. These orderings have been stable in both libraries.

Update

libc++ chose forward storage order because:

  1. It is implementable.
  2. The implementation has good compile-time performance.
  3. It gives clients of libc++ something that is intuitive and controllable, should they care about the order of the storage, and are willing to depend on it while using libc++, despite its being unspecified.

In short, the implementor of the libc++ tuple merely felt that storing the objects in the order the client (implicitly) specified was the quality thing to do.

Community
  • 1
  • 1
Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577
  • Maybe it's because I don't grok TMP at all, but I don't see where the linked post says why libc++ chose forward order. It explains why a non-recursive tuple implementation is good (which makes sense to me in principle, though I find the linked libc++ code for it totally unreadable) and then mentions at the end that libc++ uses forward order without any explanation. Is there meant to be an implication that forward order is the "obvious implementation" of a non-recursive tuple? – Ixrec Dec 27 '14 at 22:53