29 char* buffer =
new char[n *
sizeof(*first)];
33 for (
size_t length(1); length < n; length <<= 1) {
36 for (
size_t counter(n / (length << 1)); counter; --counter) {
37 Iterator right(left + length), end(right + length);
38 merge(left, right, end, buffer);
43 if ((n & ((length << 1) - 1)) > length)
44 merge(left, left + length, last, buffer);
57void merge(Iterator l, Iterator r,
const Iterator e,
char b[]) {
59 auto p(
reinterpret_cast<std::remove_reference_t<decltype(*l)
>*>(b)), c(p);
61 for (Iterator t(l); r != t; ++t) *p++ = std::move(*t);
64 while (e != r && c != p) *l++ = std::move(*r < *c ? *r++ : *c++);
67 while (e != r) *l++ = std::move(*r++);
69 while (c != p) *l++ = std::move(*c++);