can someone help me understand why my compiler can't/doesn't deduce this? (using g++ 7.3)
Does not work:
#include <array>
std::array<std::array<double,2>,2> f() {
return {{0,0},{0,0}};
}
Works fine:
#include <array>
std::array<std::array<double,2>,2> f() {
return {std::array<double,2>{0,0},{0,0}};
}
Also weirdly this fails too:
#include <array>
std::array<std::array<double,2>,2> f() {
return std::array<std::array<double,2>,2>{{0,0},{0,0}};
}
@1201ProgramAlarm pointed out that adding another set of curly braces works:
#include <array>
std::array<std::array<double,2>,2> f() {
return {{{0,0},{0,0}}};
}
It's using aggregate initialization, because std::array
has no constructor for brace-init-list. That's fine, but then why/how does this work?
std::array<double,2> x{1,2};
why does it handle this case but not the nested case?
typedef double mat[2][2];
? – Ryter