A get_extents helper function for Boost.MultiArray in C++
Avoid unnecessary temporary variables
There still is no need for the temporary vector shape_list, just use std::copy_n:
boost::detail::multi_array::extent_gen&lt;NumDims&gt; output;
std::copy_n(input.shape(), NumDims, output.ranges_.begin());

Please take some time to look at the list of all the STL algorithms. There are lots of useful functions there that will save you a lot of time. You don't have to remember them all, but get a feel for the type of functionality it provides, and next time you have a problem you might remember that some existing algorithm might solve it for you. The World Map of C++ STL Algorithms is also a great resource to build intuition for it.