Is it possible to limit the vector.max_size() in order to limit the growth of a vector?
If not, is having a function to watch the vector.capacity() to ensure it doesn’t go over a determined amount a viable substitute?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sort of. You can write a custom allocator and use it in a
std::vector(the second template argument of the vector). The allocator needs to satisfy these requirements. However, doing this properly isn’t simple. And yourvectorwouldn’t just ignorepush_backafter the max size was met, it would throw.