In the implementation and in a follow example of std::uninitialised_fill()
in cppreference.com I am having some trouble in understanding a couple of things:
template<class ForwardIt, class T>
void uninitialized_fill(ForwardIt first, ForwardIt last, const T& value)
{
typedef typename std::iterator_traits<ForwardIt>::value_type Value;
ForwardIt current = first;
try {
for (; current != last; ++current) {
::new (static_cast<void*>(&*current)) Value(value);
}
....
}
I don't understand why in the static_cast
I need to do (&*)
?
Stroustrup in his book states "the curious construct (&*) takes care of iterator that are not pointers. In that case we need to take the address of the element obtained by dereference to get a pointer".
I have three questions
- What does it he mean "Iterators that are not pointers"? What else could they be other than a generalisation of pointers? More confusing, we need to take address of element obtained by dereferenced to get a pointer.
- Syntactically
::new
andnew
are the same. There is a particular reason using::
? - Is
get_temporary_buffer(
) to allocate storage conceptually the same asMyClass * p3 = (MyClass*) ::operator new (sizeof(MyClass));
or are they two different things?
Please could you provide a little example for all questions?