Title
How do uninitialized memory algorithms obtain pointer without undefined behavior?
Status
new
Section
[specialized.algorithms]
Submitter
Alisdair Meredith

Created on 2018-02-12.00:00:00 last changed 74 months ago

Messages

Date: 2018-02-15.00:00:00

[ 2018-02-20, Priority set to 3 after mailing list discussion ]

Date: 2020-05-02.19:53:28

A typical specification of the algorithms for initializing raw memory in <memory> looks like:

Effects: Equivalent to:

for (; first != last; ++first)
  ::new (static_cast<void*>(addressof(*first)))
    typename iterator_traits<ForwardIterator>::value_type;

However, this hides a nasty question:

How do we bind a reference to an uninitialized object when dereferencing our iterator, so that static_cast<void*>(addressof(*first)) does not trigger undefined behavior on the call to *first?

When pointers are the only iterators we cared about, we could simply cast the iterator value to void* without dereferencing. I don't see how to implement this spec safely without introducing another customization point for iterators that performs the same function as casting a pointer to void* in order to get the address of the element.

History
Date User Action Args
2018-03-03 15:21:00adminsetmessages: + msg9696
2018-02-12 00:00:00admincreate