Quote:
Originally posted by mclark
Now down to the tricky part of my question, intrestingly reserve throws length_error if the size request is larger than max_size. If the std::vector<>:: push_back (or any other modifier) uses reserve internally and their has been enough free memory that the new requested size (based on the growth strategy) is both larger than max_size and unsatisifiable by the allocator - do I get a 'bad_alloc', 'length_error' or is it all just implementation dependent.
I've had a quick look at the standard and I can't find the answer. As you say, it boils down to whether internal reallocation uses reserve(), and, if so, does it check for a possible length_error before it does it? I couldn't find anything covering that. All it says about the allocator is "reserve() uses Allocator::allocate() which may throw an appropriate exception". I did try this out once but, of course, being VC++, it doesn't throw bad_alloc, it returns NULL, so the test was inconclusive, and I didn't have time to try to persuade VC++ to throw the exception like it's supposed to.