Created
January 21, 2014 23:14
-
-
Save johnbartholomew/8550473 to your computer and use it in GitHub Desktop.
Testing nested initializer-lists without initializer-list constructors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah... I just tested on VC2013... VC bug? Obscure POD rules?