mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
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:
parent
a795017416
commit
9a5a13854d
13 changed files with 117 additions and 46 deletions
|
@ -63,7 +63,7 @@ main()
|
|||
|
||||
{
|
||||
ctl::optional<ctl::string> x("world");
|
||||
ctl::optional<ctl::string> y(std::move(x));
|
||||
ctl::optional<ctl::string> y(ctl::move(x));
|
||||
if (!y)
|
||||
return 9;
|
||||
if (!y.has_value())
|
||||
|
@ -87,7 +87,7 @@ main()
|
|||
{
|
||||
ctl::optional<ctl::string> x("hello");
|
||||
ctl::optional<ctl::string> y;
|
||||
y = std::move(x);
|
||||
y = ctl::move(x);
|
||||
if (!y)
|
||||
return 16;
|
||||
if (!y.has_value())
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "ctl/string.h"
|
||||
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -211,7 +210,7 @@ main()
|
|||
|
||||
{
|
||||
String s = "hello";
|
||||
String s2 = std::move(s);
|
||||
String s2 = ctl::move(s);
|
||||
if (s2 != "hello")
|
||||
return 47;
|
||||
if (!s.empty())
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
#include "ctl/string_view.h"
|
||||
|
||||
#include <__utility/move.h>
|
||||
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
@ -90,7 +88,7 @@ main(int argc, char* argv[])
|
|||
|
||||
{
|
||||
ctl::string_view s = "hello";
|
||||
ctl::string_view s2 = std::move(s);
|
||||
ctl::string_view s2 = ctl::move(s);
|
||||
if (s2 != "hello")
|
||||
return 16;
|
||||
if (s.empty())
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "ctl/unique_ptr.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include <__type_traits/is_same.h>
|
||||
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
|
@ -32,7 +32,7 @@ template<typename T, typename... Args>
|
|||
Ptr<T>
|
||||
Mk(Args&&... args)
|
||||
{
|
||||
return ctl::make_unique<T, Args...>(std::forward<Args>(args)...);
|
||||
return ctl::make_unique<T, Args...>(ctl::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -161,7 +161,7 @@ main()
|
|||
// shouldn't compile
|
||||
x = y;
|
||||
#endif
|
||||
x = std::move(y);
|
||||
x = ctl::move(y);
|
||||
if (g != 1)
|
||||
return 10;
|
||||
if (y)
|
||||
|
|
|
@ -50,7 +50,7 @@ main()
|
|||
ctl::string yo = "foo";
|
||||
ctl::vector<ctl::string> A;
|
||||
A.push_back("fun");
|
||||
A.push_back(std::move(yo));
|
||||
A.push_back(ctl::move(yo));
|
||||
if (yo != "")
|
||||
return 5;
|
||||
A.emplace_back("bar");
|
||||
|
@ -94,7 +94,7 @@ main()
|
|||
A.push_back(1);
|
||||
A.push_back(2);
|
||||
A.push_back(3);
|
||||
ctl::vector<int> B(std::move(A));
|
||||
ctl::vector<int> B(ctl::move(A));
|
||||
if (A.size() != 0)
|
||||
return 17;
|
||||
if (B.size() != 3)
|
||||
|
@ -122,7 +122,7 @@ main()
|
|||
A.push_back(2);
|
||||
A.push_back(3);
|
||||
ctl::vector<int> B;
|
||||
B = std::move(A);
|
||||
B = ctl::move(A);
|
||||
if (A.size() != 0)
|
||||
return 22;
|
||||
if (B.size() != 3)
|
||||
|
@ -286,7 +286,7 @@ main()
|
|||
A.push_back(2);
|
||||
A.push_back(3);
|
||||
ctl::vector<int> B;
|
||||
B = std::move(A);
|
||||
B = ctl::move(A);
|
||||
if (A.size() != 0)
|
||||
return 63;
|
||||
if (B.size() != 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue