May STL iterator methods throw an exception

后端 未结 4 756
抹茶落季
抹茶落季 2020-12-09 17:07

Destructors may not throw exceptions (so stack unwinding can complete during exception handling), and must deallocate any resources allocated to the object (so no resources

相关标签:
4条回答
  • 2020-12-09 17:16

    The destructor would therefore use the following iterator-related methods

    No it would not. The destructor of that object would just call the destructor of the container, which would in turn be guaranteed to not throw an exception.

    If you use RAII correctly, you will almost never run into a scenario where you have to explicitly release resources. This could be achieved by have the container store shared_ptr or unique_ptr, or by using something like Boost.Pointer Container.

    0 讨论(0)
  • 2020-12-09 17:19

    According to http://www.tenouk.com/Module31.html these operations (for '*' and '->' it depends also on the type stored) are no throw for STL containers.

    0 讨论(0)
  • 2020-12-09 17:32

    operator++ for a valid iterator

    The C++ standard (I refer to N3290 draft) does not give nothrow guarantee for increment operator of iterators.

    For example, std::istreambuf_iterator::operator++ effects in call to std::basic_streambuf::sbumpc. The sbumpc may call uflow which in turn may throw exception.

    0 讨论(0)
  • 2020-12-09 17:40

    no copy constructor or assignment operator of a returned iterator throws an exception

    That's from the C++03 standard. I don't think that the standard goes any further than that.

    Btw. it's 23.1.10

    0 讨论(0)
提交回复
热议问题