Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing nested initializer-lists without initializer-list constructors.
/* Compiles and works with recent GCC and Clang in C++11 mode.
* $ g++ --version
* g++ (GCC) 4.8.2 20131219 (prerelease)
*
* $ clang++ --version
* clang version 3.4 (tags/RELEASE_34/final)
*/
#include <vector>
#include <iostream>
struct Vec3 {
Vec3(int x, int y, int z): x(x), y(y), z(z) {}
int x;
int y;
int z;
};
struct Mat3 {
Mat3(Vec3 a, Vec3 b, Vec3 c): a(a), b(b), c(c) {}
Vec3 a;
Vec3 b;
Vec3 c;
};
static std::ostream &operator<<(std::ostream &ss, const Vec3 &v) {
return (ss << "(" << v.x << " " << v.y << " " << v.z << ")");
}
static std::ostream &operator<<(std::ostream &ss, const Mat3 &m) {
return (ss << m.a << "\n" << m.b << "\n" << m.c << "\n");
}
static void test_vec3() {
std::vector<Vec3> vs{
{ 1,2,3 },
{ 2,3,4 },
{ 3,4,5 },
};
std::cout << "std::vector<Vec3>:\n";
for (const auto &v : vs) {
std::cout << v << "\n";
}
}
static void test_mat3() {
std::vector<Mat3> ms{
{
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 },
},
{
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
},
};
std::cout << "std::vector<Mat3>:\n";
for (const auto &m : ms) {
std::cout << m;
}
}
int main() {
test_vec3();
test_mat3();
return 0;
}
@Groovounet

This comment has been minimized.

Copy link

@Groovounet Groovounet commented Jan 21, 2014

Ah... I just tested on VC2013... VC bug? Obscure POD rules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment