为什么libstdc ++以相反的顺序存储std :: tuple元素? [英] Why does libstdc++ store std::tuple elements in reverse order?

查看:178
本文介绍了为什么libstdc ++以相反的顺序存储std :: tuple元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://flamingdangerzone.com/cxx11/2012/07/06 /optimal-tuple-i.html ,关于std :: tuple ...


libstdc ++总是放置成员以相反的顺序,libc ++总是按给定的顺序放置成员


假设这是真的,为什么libstdc ++使用反向顺序?



Bonus:有没有任何实现因为任何原因而更改了std :: tuple排序?

解决方案

请参见此回答为什么libc ++选择转发订单。至于为什么libstdc ++选择逆序,这可能是因为这是在可变参数模板提议中演示的,并且是更明显的实现。



Bonus:



libc ++选择转发存储因为:


  1. 可实现

  2. 实施具有良好的编译时性能。 / li>
  3. 它为libc ++的客户端提供了直观和可控的,如果他们关心存储的顺序,并且愿意依赖它,同时使用libc ++,尽管它未指定。 li>

简而言之,libc ++ tuple 的实现只是觉得存储对象客户端(隐式地)指定的顺序是质量要做的事情。


According to http://flamingdangerzone.com/cxx11/2012/07/06/optimal-tuple-i.html, 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?

解决方案

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.

这篇关于为什么libstdc ++以相反的顺序存储std :: tuple元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆