std :: pair和std :: tuple之间的区别只有两个成员? [英] Difference between std::pair and std::tuple with only two members?
问题描述
只有两个成员的 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...)
推荐答案
有一些区别:
-
std :: tuple
永远不会被标准布局(至少,不是按标准)。如果T
和都是标准布局,则每个
std :: pair< T,Y&
std::tuple
can never be be standard-layout (at least, it's not required to be by the standard). Everystd::pair<T, Y>
is standard-layout if bothT
andY
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屋!