我想知道元组是否可以通过初始化列表初始化(更准确地说 - 初始化列表的initializer_list)?考虑元组定义:
typedef std::tuple< std::array<short, 3>,
std::array<float, 2>,
std::array<unsigned char, 4>,
std::array<unsigned char, 4> > vertex;
Run Code Online (Sandbox Code Playgroud)
有没有办法做到以下几点:
static vertex const nullvertex = { {{0, 0, 0}},
{{0.0, 0.0}},
{{0, 0, 0, 0}},
{{0, 0, 0, 0}} };
Run Code Online (Sandbox Code Playgroud)
我只想实现使用struct而不是tuple的相同功能(因此只有数组由initializer_list初始化):
static struct vertex {
std::array<short, 3> m_vertex_coords;
std::array<float, 2> m_texture_coords;
std::array<unsigned char, 4> m_color_1;
std::array<unsigned char, 4> m_color_2;
} const nullvertex = {
{{0, 0, 0}},
{{0.0, 0.0}},
{{0, 0, 0, 0}},
{{0, 0, 0, 0}}
};
Run Code Online (Sandbox Code Playgroud)
没有理由我必须使用元组,只是想知道.我问,因为我无法通过我尝试进行这种元组初始化而生成的g ++模板错误.
@Motti:所以我错过了统一初始化的正确语法 - …