c++ - 元组没有按顺序构建?

标签 c++ constructor stdtuple

以下program :

#include <iostream>
#include <tuple>

struct A {
    A() { std::cout << "A constructor\n"; }
};

struct B {
    B() { std::cout << "B constructor\n"; }
};

int main() {
    std::tuple<A, B> t;
}

在不同的编译器上给出不同的输出:

# libstdc++
B constructor
A constructor
# libc++
A constructor
B constructor

这看起来很奇怪...我认为标准会保证元组元素按顺序构造,例如 A、B、...、Y、Z?

最佳答案

std::tuple 构造顺序当前为 unspecified .

对其订单作出具体决定的提案已 submitted向委员会提交,但在此之前不应依赖该命令。

关于c++ - 元组没有按顺序构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32192809/

相关文章:

c++ - 如何将方法结果作为参数传递给 C++ 中的基类构造函数?

c++ - 使用 std::tuple_element 时无效使用不完整类型的问题

c++ - 将原始对象写入/读取到文件

c++ - 是否可以编写通用的重新绑定(bind)模板?

c++ - VS2008 C++ 编译器错误?

c++ - 默认的默认构造函数是否将变量初始化为零?

c++ - cstdlib 和 stdlib.h 有什么区别?

c++ - 是否可以将函数指针转换为整数?

c++ - 只有两个成员的 std::pair 和 std::tuple 之间的区别?

c++ - 通过模板参数给定其长度,在编译时生成相同类型的 std::tuple