I'm aware that dereferencing a pointer or iterator that points to uninitialized memory is illegal, unless it's a special iterator such as std::raw_storage_iterator.
It then seems strange to me that the std::uninitialized_ family of algorithms seem to do this?
E.g. The Equivalent behaviour for std::uninitialized_copy under § 23.10.10.4 of the C++17 standard is stated as this:
template <class InputIterator, class ForwardIterator> ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);Effects: As if by:
for (; first != last; ++d_first, (void) ++first) ::new (static_cast<void*>(addressof(*result))) typename iterator_traits<ForwardIt>::value_type(*first);
Where result is a ForwardIterator to a range of uninitialized memory.
Similarly, en.cppreference's example and GCC 7.5 (line 83) do this. I must be missing something; why is this legal? I'm specifically referring to:
static_cast<void*>(addressof(*result))