Let’s face it, the std::array and std::vector containers suck for multi-dimensional data. The situation is so bad it makes me long for the days of T array[N][M]; and T** array. Well, it turns out, to fix our modern C++11 and C++14 array containers, doesn’t take much work.

The Problem

Defining a multi-dimensional array using C++11/14 containers is no good:

The good old days (which can still be used) were much better in some ways:

And worse in other ways:

The Solution

Why not a syntax for multi-dimensional container style arrays and vectors? You could get the best of both worlds like this:

The Code

It turns out, with the help of alias templates, and some class based SFINAE not much code is needed to achieve our desired syntax.

multi::array:

multi::vector:

We don’t need to reinvent the same data structures over and over when we can just use what we already have and let the templates do all the work.

Repo for this code: https://github.com/brianrackle/multi