Is uninitialized_copy() exception-safe?

258 views Asked by At

MSDN and other places say that uninitialized_copy provides a strong exception guarantee, but other C++ references don't.

Is this in fact guaranteed by C++, or not?

1

There are 1 answers

1
user541686 On BEST ANSWER

Yes, C++03 does provide this guarantee, but it's worth double-checking for your implementations.

From a draft copy I had on my machine, 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.)

So yes, that means the "possible implementation" you see on some pages can be incorrect.