简体   繁体   English

uninitialized_copy()异常安全吗?

[英]Is uninitialized_copy() exception-safe?

MSDN and other places say that uninitialized_copy provides a strong exception guarantee, but other C++ references don't . MSDN其他地方uninitialized_copy提供了强大的异常保证,但其他 C ++引用却没有

Is this in fact guaranteed by C++, or not? 这实际上是否由C ++保证?

Yes, C++03 does provide this guarantee, but it's worth double-checking for your implementations. 是的,C ++ 03确实提供了这种保证,但值得仔细检查您的实现。

From a draft copy I had on my machine, 20.4.4: 从我在机器上的草稿中,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 . 在以下算法中用作形式模板参数的所有迭代器都需要让它们的operator*返回一个定义了operator&的对象,并返回一个指向T的指针。
In the algorithm uninitialized_copy , the formal template parameter InputIterator is required to satisfy the requirements of an input iterator (24.1.1). uninitialized_copy算法中,正式模板参数InputIterator需要满足输入迭代器(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. 在以下所有算法中,正式模板参数ForwardIterator需要满足前向迭代器(24.1.3)的要求,并且还要满足可变迭代器(24.1)的要求,并且要求具有no的属性。从有效迭代器的增量,赋值,比较或取消引用中抛出异常。
In the following algorithms, if an exception is thrown there are no effects. 在以下算法中,如果抛出异常,则没有效果。

  • uninitialized_copy (etc.) uninitialized_copy (等)

So yes, that means the "possible implementation" you see on some pages can be incorrect. 所以,是的,这意味着您在某些页面上看到的“可能实现”可能不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM