c++ - uninitialized_copy() 异常安全吗?

标签 c++ exception exception-safety

MSDNother 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 to T.
In the algorithm uninitialized_copy, the formal template parameter InputIterator is required to satisfy the requirements of an input iterator (24.1.1).
In all of the following algorithms, the formal template parameter ForwardIterator 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/

相关文章:

c++ - 使用 WriteFile 填充集群

c++ - 如何在 C++ 中将 image.jpg 转换为 image.ppm

c# - A try-catch one liner (like "??"or ternary operator)

exception - Junit 异常处理

android - SharedPreferences getLong() -> java.lang.String 无法转换为 java.lang.Long。怎么修?

c++ - 从两个 vector 中删除垂直反转的重复项

c++ - OMNeT++中不同类型数据包之间的冲突

java - Java异常安全可以变得不那么难看吗?

c++ - std::unordered_map::merge() 的安全性

c++ - 声明 POD 类型会抛出异常吗?