Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix typo in code example; add #include <cstddef> to same example

...

Code Block
bgColor#FFcccc
langcpp
#include <cstddef>
#include <new>

struct S {
  S ();
  ~S ();
};

void f() {
  const unsigned N = 32;
  alignas(S) unsigned char buffer[sizeof(S) * N];
  S *sp = ::new (buffer) S[N];
 
  // ...
  // Destroy elements of the array.
  for (size_t i = 0; i != nN; ++i) {
    sp[i].~S();
  }
}

Compliant Solution (Clang/GCC)

...