How to initialize a nested (2D) std::array
via an initializer-list?
template <std::size_t W, std::size_t H>
class Block
{
std::array<std::array<int, W>, H> block;
public:
template <typename ...E>
Block(E&&...e) : block {{std::forward<E>(e)...}} {}
};
The class Block
should able to initialize block
member as below:
Block<3, 2> b {{ {1, 2, 3}, {4, 5, 6} }};
Note: We have the ability to initialize the std::array
directly in C++11:
std::array<std::array<int, 3>, 2> b {{ {1, 2, 3}, {4, 5, 6} }};
I'm using gcc-4.9.0