CTL: utility.h, use ctl::swap in string (#1227)

* Add ctl utility.h

Implements forward, move, swap, and declval. This commit also adds a def
for nullptr_t to cxx.inc. We need it now because the CTL headers stopped
including anything from libc++, so we no longer get their basic types.

* Use ctl::swap in string

The STL spec says that swap is located in the string_view header anyawy.
Performance-wise this is a noop, but it’s slightly cleaner.
This commit is contained in:
Steven Dee (Jōshin) 2024-06-18 22:00:59 -07:00 committed by GitHub
parent a795017416
commit 9a5a13854d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 117 additions and 46 deletions

View file

@ -3,9 +3,7 @@
#ifndef COSMOPOLITAN_CTL_OPTIONAL_H_
#define COSMOPOLITAN_CTL_OPTIONAL_H_
#include "new.h"
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/swap.h>
#include "utility.h"
namespace ctl {
@ -173,7 +171,7 @@ struct vector
return;
T* newP = new T[c2];
for (size_t i = 0; i < n; ++i)
newP[i] = std::move(p[i]);
newP[i] = ctl::move(p[i]);
delete[] p;
p = newP;
c = c2;
@ -197,7 +195,7 @@ struct vector
c2 += c2 >> 1;
reserve(c2);
}
new (&p[n]) T(std::forward<T>(e));
new (&p[n]) T(ctl::forward<T>(e));
++n;
}
@ -209,7 +207,7 @@ struct vector
c2 += c2 >> 1;
reserve(c2);
}
new (&p[n]) T(std::forward<Args>(args)...);
new (&p[n]) T(ctl::forward<Args>(args)...);
++n;
}
@ -236,9 +234,9 @@ struct vector
void swap(vector& other) noexcept
{
std::swap(n, other.n);
std::swap(c, other.c);
std::swap(p, other.p);
ctl::swap(n, other.n);
ctl::swap(c, other.c);
ctl::swap(p, other.p);
}
};