std :: pair和std :: tuple之间的区别只有两个成员? [英] Difference between std::pair and std::tuple with only two members?

查看:1181
本文介绍了std :: pair和std :: tuple之间的区别只有两个成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有两个成员的 std :: pair std :: tuple 之间有区别吗? (除了明显的 std :: pair 需要两个且只有两个成员,而 tuple 可能有更少...)

Is there a difference between an std::pair and an std::tuple with only two members? (Besides the obvious that std::pair requires two and only two members and tuple may have less...)

推荐答案

有一些区别:


  1. std :: tuple 永远不会被标准布局(至少,不是按标准)。如果 T 都是标准布局,则每个 std :: pair< T,Y&

  1. std::tuple can never be be standard-layout (at least, it's not required to be by the standard). Every std::pair<T, Y> is standard-layout if both T and Y are standard-layout.

获得对的内容会更容易一些 code>比 tuple 。您必须在 tuple 案例中使用函数调用,而案例只是一个成员字段。 p>

It's a bit easier to get the contents of a pair than a tuple. You have to use a function call in the tuple case, while the pair case is just a member field.

但是就是这样。

这篇关于std :: pair和std :: tuple之间的区别只有两个成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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