1

There are two almost identical algorithms in STL:

https://en.cppreference.com/w/cpp/memory/uninitialized_default_construct https://en.cppreference.com/w/cpp/memory/uninitialized_value_construct

The only difference is:

for (; current != last; ++current) {
    ::new (static_cast<void*>(std::addressof(*current))) Value();
}

vs.

for (; current != last; ++current) {
    ::new (static_cast<void*>(std::addressof(*current))) Value;
}

Could you explain the difference?

And for what reason they exist along?

Name
  • 124
  • 12
  • https://en.cppreference.com/w/cpp/language/value_initialization versus https://en.cppreference.com/w/cpp/language/default_initialization – Jarod42 Dec 11 '20 at 23:31
  • 2
    `*new int()` is zero whereas `*new int` is UB as reading uninitialized variable – Jarod42 Dec 11 '20 at 23:33
  • @Jarod42 for complex types there is absolutely any difference, right? – Name Dec 11 '20 at 23:37
  • I don't think the suggested question answers when the above 2 functions would be used – Baiyan Huang Dec 11 '20 at 23:40
  • Found: https://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new/620402#620402 – Name Dec 11 '20 at 23:44

0 Answers0