Stl and exceptions

If I use reserve () to reserve enough elements for a vector, does push_back () (or insert ()) throw any exceptions?

Is there a link somewhere that indicates which stl function throws / throws any exceptions?

Thank.

+3
source share
3 answers

If I use reserve () to reserve enough elements for a vector, does push_back () (or insert ()) throw any exceptions?

There is no need to redistribute, so the vector itself will not throw any exceptions. The elements you paste can throw exceptions when copying to a vector, so push_backthey insertcan still throw exceptions.

Is there a link somewhere that indicates which stl function throws / throws any exceptions?

Yes, the C ++ standard contains this information.

+5
source

, push_back , .

std::vector vector, , push_back insert, .

, , ++ .

+4

I can only answer the first of two questions.

The method reserve(K)allocates enough space on vectorto place elements Kwithout costly redistribution, but vectorcan increase in size if enough inserts are made.

0
source

Source: https://habr.com/ru/post/1763780/


All Articles