A get_extents helper function for Boost.MultiArray in C++ This is a follow-up question for A filled_multi_array Template Function for Boost.MultiArray in C++. Based on G. Sliepen's answer, there is another get_extents template function mentioned for handling retrieving boost::detail::multi_array::extent_gen&lt;NumDims&gt; type size information from a multi_array. I am trying to implement this get_extents template function here.
template&lt;class T, std::size_t NumDims&gt;
auto get_extents(const boost::multi_array&lt;T, NumDims&gt;&amp; input) {
    boost::detail::multi_array::extent_gen&lt;NumDims&gt; output;
    std::vector&lt;size_t&gt; shape_list;
    for (size_t i = 0; i &lt; NumDims; i++)
    {
        shape_list.push_back(input.shape()[i]);
    }
    std::copy(shape_list.begin(), shape_list.end(), output.ranges_.begin());
    return output;
}

I am trying to copy shape content into the output object. In general cases, boost::detail::multi_array::extent_gen object is always constructed by boost::extents[][][].... However, I am not sure how to use boost::extents in this context and I fill the values of shape information into output.ranges_ instead. It works with the following testing code.
auto filled_multi_array1 = filled_multi_array(boost::extents[3][4][2], 1.0);
auto filled_multi_array2 = filled_multi_array(get_extents(filled_multi_array1), 2.0);

//  Checking shape
std::cout &lt;&lt; &quot;filled_multi_array2.shape()[0]:&quot; &lt;&lt; filled_multi_array2.shape()[0] &lt;&lt; std::endl;
std::cout &lt;&lt; &quot;filled_multi_array2.shape()[1]:&quot; &lt;&lt; filled_multi_array2.shape()[1] &lt;&lt; std::endl;
std::cout &lt;&lt; &quot;filled_multi_array2.shape()[2]:&quot; &lt;&lt; filled_multi_array2.shape()[2] &lt;&lt; std::endl;

for (decltype(filled_multi_array2)::index i = 0; i != filled_multi_array2.shape()[0]; ++i)
    for (decltype(filled_multi_array2)::index j = 0; j != filled_multi_array2.shape()[1]; ++j)
        for (decltype(filled_multi_array2)::index k = 0; k != filled_multi_array2.shape()[2]; ++k)
            std::cout &lt;&lt; filled_multi_array2[i][j][k] &lt;&lt; std::endl;

All suggestions are welcome.
The summary information:

Which question it is a follow-up to?
A filled_multi_array Template Function for Boost.MultiArray in C++

What changes has been made in the code since last question?
The extent_gen function implementation is the main part in this question.

Why a new review is being asked for?
The shape_list which type is std::vector&lt;size_t&gt; in get_extents function is used just for copying shape data into output.ranges_. The reason why I create a std::vector for this operation is that there is neither .begin() function nor .end() function in input.shape(). Something like std::copy(input.shape().begin(), input.shape().end(), output.ranges_.begin()); doesn't work. If there is any possible improvement, please let me know.
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.