Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As specified in the standard, <code>max_size()</code> is the maximum number of elements that the container can possibly store:</p> <blockquote> <p><code>distance(begin(), end())</code> for the largest possible container</p> </blockquote> <p>(C++11, [container.requirements.general], table 96)</p> <p>For <code>array</code>, which is a fixed-size container, it coincides with <code>size()</code>, while it is completely different for dynamic containers, like <code>std::vector</code> (where it will return something like the size of the virtual address space divided by the size of the element).</p> <p>You can find all the specifications of the containers in the C++ standard (which is quite expensive, but its drafts are freely available online), although it's just a normative specification which tends not to explain well the rationale behind some decisions (and is deliberately vague on the implementation of the containers).</p> <p>Still, for the difference between <code>std::array</code> and <code>std::vector</code>, it's because <code>std::array</code> is intended to store the elements without resorting to the heap, providing a same-performance alternative to a local C-style array, while <code>std::vector</code> uses the heap to store the elements, which allows much more flexibility but comes at a cost. See <a href="https://stackoverflow.com/a/4424658/214671">this answer of mine</a> for a more detailed comparison between <code>std::array</code> and <code>std::vector</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload