MSDN和 other places假设 uninitialized_copy
提供了强大的异常保证,但是 other C++ 引用 don't .
这实际上是由 C++ 保证的吗?
最佳答案
是的,C++03 确实提供了这种保证,但是值得仔细检查您的实现。
从我机器上的一份草稿拷贝,20.4.4:
All the iterators that are used as formal template parameters in the following algorithms are required to have their
operator*
return an object for which operator& is defined and returns a pointer toT
.
In the algorithmuninitialized_copy
, the formal template parameterInputIterator
is required to satisfy the requirements of an input iterator (24.1.1).
In all of the following algorithms, the formal template parameterForwardIterator
is required to satisfy the requirements of a forward iterator (24.1.3) and also to satisfy the requirements of a mutable iterator (24.1), and is required to have the property that no exceptions are thrown from increment, assignment, comparison, or dereference of valid iterators.
In the following algorithms, if an exception is thrown there are no effects.
uninitialized_copy
(etc.)
是的,这意味着您在 some pages 上看到的“可能的实现”可能不正确。
关于c++ - uninitialized_copy() 异常安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11985330/