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

@ -2,9 +2,7 @@
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef COSMOPOLITAN_CTL_UNIQUE_PTR_H_
#define COSMOPOLITAN_CTL_UNIQUE_PTR_H_
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/swap.h>
#include "utility.h"
namespace ctl {
@ -36,11 +34,11 @@ struct unique_ptr
}
constexpr unique_ptr(pointer p, auto&& d) noexcept
: p(p), d(std::forward<decltype(d)>(d))
: p(p), d(ctl::forward<decltype(d)>(d))
{
}
constexpr unique_ptr(unique_ptr&& u) noexcept : p(u.p), d(std::move(u.d))
constexpr unique_ptr(unique_ptr&& u) noexcept : p(u.p), d(ctl::move(u.d))
{
u.p = nullptr;
}
@ -89,7 +87,7 @@ struct unique_ptr
inline void swap(unique_ptr& r) noexcept
{
using std::swap;
using ctl::swap;
swap(p, r.p);
swap(d, r.d);
}
@ -115,7 +113,7 @@ struct unique_ptr
}
inline element_type& operator*() const
noexcept(noexcept(*std::declval<pointer>()))
noexcept(noexcept(*ctl::declval<pointer>()))
{
if (!p)
__builtin_trap();
@ -134,7 +132,7 @@ template<typename T, typename... Args>
inline unique_ptr<T>
make_unique(Args&&... args)
{
return unique_ptr<T>(new T(std::forward<Args>(args)...));
return unique_ptr<T>(new T(ctl::forward<Args>(args)...));
}
template<typename T>