#include <initializer_list>
#include <algorithm>
#include <iostream>
#include <memory>
template <class T> class test
{
private:
std::unique_ptr<T[]> arr;
public:
std::size_t rows;
std::size_t cols;
test(std::initializer_list<std::initializer_list<T>> r) : rows(r.size())
{
using init = const std::initializer_list<T>;
cols = std::max_element(r.begin(), r.end(), [](init& lhs, init& rhs)
{return lhs.size() < rhs.size();}
)->size();
arr = std::unique_ptr<T[]>(new T[rows*cols]);
auto source = r.begin();
auto dest = &arr[0];
do {
std::copy(source->begin(), source->end(), dest);
dest += cols;
} while(++source != r.end());
}
T* operator[](std::size_t index)
{
return &arr[0] + index*cols;
}
};
int main()
{
test<int> a = {{1, 2, 3}, {4, 5, 6}};
for(std::size_t i = 0; i < a.rows; ++i) {
for(std::size_t j = 0; j < a.cols; ++j)
std::cout << a[i][j] << ' ';
std::cout << '\n';
}
}
I2luY2x1ZGUgPGluaXRpYWxpemVyX2xpc3Q+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlIDxjbGFzcyBUPiBjbGFzcyB0ZXN0CnsKcHJpdmF0ZToKICAgIHN0ZDo6dW5pcXVlX3B0cjxUW10+IGFycjsKcHVibGljOgogICAgc3RkOjpzaXplX3Qgcm93czsKICAgIHN0ZDo6c2l6ZV90IGNvbHM7CiAgICB0ZXN0KHN0ZDo6aW5pdGlhbGl6ZXJfbGlzdDxzdGQ6OmluaXRpYWxpemVyX2xpc3Q8VD4+IHIpIDogcm93cyhyLnNpemUoKSkKICAgIHsKICAgICAgICB1c2luZyBpbml0ID0gY29uc3Qgc3RkOjppbml0aWFsaXplcl9saXN0PFQ+OwogICAgICAgIGNvbHMgPSBzdGQ6Om1heF9lbGVtZW50KHIuYmVnaW4oKSwgci5lbmQoKSwgW10oaW5pdCYgbGhzLCBpbml0JiByaHMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7cmV0dXJuIGxocy5zaXplKCkgPCByaHMuc2l6ZSgpO30KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICktPnNpemUoKTsKICAgICAgICBhcnIgPSBzdGQ6OnVuaXF1ZV9wdHI8VFtdPihuZXcgVFtyb3dzKmNvbHNdKTsKICAgICAgICBhdXRvIHNvdXJjZSA9IHIuYmVnaW4oKTsKICAgICAgICBhdXRvIGRlc3QgPSAmYXJyWzBdOwogICAgICAgIGRvICB7CiAgICAgICAgICAgIHN0ZDo6Y29weShzb3VyY2UtPmJlZ2luKCksIHNvdXJjZS0+ZW5kKCksIGRlc3QpOwogICAgICAgICAgICBkZXN0ICs9IGNvbHM7CiAgICAgICAgfSB3aGlsZSgrK3NvdXJjZSAhPSByLmVuZCgpKTsKICAgIH0KICAgIFQqIG9wZXJhdG9yW10oc3RkOjpzaXplX3QgaW5kZXgpCiAgICB7CiAgICAgICAgcmV0dXJuICZhcnJbMF0gKyBpbmRleCpjb2xzOwogICAgfQp9OwoKaW50IG1haW4oKQp7CiAgICB0ZXN0PGludD4gYSA9IHt7MSwgMiwgM30sIHs0LCA1LCA2fX07CiAgICBmb3Ioc3RkOjpzaXplX3QgaSA9IDA7IGkgPCBhLnJvd3M7ICsraSkgewogICAgICAgIGZvcihzdGQ6OnNpemVfdCBqID0gMDsgaiA8IGEuY29sczsgKytqKQogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgYVtpXVtqXSA8PCAnICc7CiAgICAgICAgc3RkOjpjb3V0IDw8ICdcbic7CiAgICB9Cn0K