The base container adapter container container is std::stack , located in the protected section, and can be obtained by the name c (from derived classes using the fully qualified name or by introducing classes into the namespace using using derective). The default main container is std::deque . std::deque , std::list or std::vector . They all provide the member function max_size() , returning the maximum size that can be allocated. Authoritative source WRT max_size() The member function of the specified containers indicated:
Notes
This value is usually equal to std :: numeric_limits :: max () and reflects the theoretical limit on the size of the container. At run time, the size of the container may be limited to a value less than max_size () by the amount of available RAM.
So, the return value max_size() smart implementation can rely on the RAM available for hosting.
To access std::stack<>::c.max_size() , you should write a derivative from the std::stack<> class as follows:
#include <iostream> #include <stack> #include <cstdlib> template< typename type > struct my_stack : std::stack< type > { using base = std::stack< type >; using base::base; using base::operator =; std::size_t max_size() const { return base::c.max_size(); } }; int main() { my_stack< int > s; std::cout << s.max_size() << std::endl; return EXIT_SUCCESS; }
source share