Exceeding container::max_size()?

K

Kevin Goodsell

I was unable to locate the answer to this question in the (draft)
Standard or in The C++ Standard Library (Josuttis). What should occur
when one attempts to increase the size of a container beyond its max_size()?

The closest thing I found to an answer was that the reserve() member of
std::basic_string and std::vector and the resize() member of
std::basic_string throw std::length_error if the new size exceeds
max_size(). This seems likely to apply to all "growing" operations of
all containers, and is consistent with the description of
std::length_error, but I can't find anything that explicitly states this.

Thanks.

-Kevin
 
V

Victor Bazarov

Kevin Goodsell said:
I was unable to locate the answer to this question in the (draft)
Standard or in The C++ Standard Library (Josuttis). What should occur
when one attempts to increase the size of a container beyond its
max_size()?

AFAIUI, 'max_size' is not a requirement but rather a statement of fact.
You should never be able to create a container of that size -- you will
most likely run out of memory first.
The closest thing I found to an answer was that the reserve() member of
std::basic_string and std::vector and the resize() member of
std::basic_string throw std::length_error if the new size exceeds
max_size(). This seems likely to apply to all "growing" operations of
all containers, and is consistent with the description of
std::length_error, but I can't find anything that explicitly states this.

23.2.4.2/4 for 'std::vector'. 21.3.3/6 for 'std::basic_string'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top