Refactor and improve CTL and other code

This commit is contained in:
Justine Tunney 2024-06-04 05:41:53 -07:00
parent 1d8f37a2f0
commit 9906f299bb
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
25 changed files with 5768 additions and 5350 deletions

View file

@ -1,19 +1,20 @@
// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; coding:utf-8 -*-
// vi: set et ft=c++ ts=4 sts=4 sw=4 fenc=utf-8
//
// Copyright 2024 Mozilla Foundation
// Copyright 2024 Justine Alexandra Roberts Tunney
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Permission to use, copy, modify, and/or distribute this software for
// any purpose with or without fee is hereby granted, provided that the
// above copyright notice and this permission notice appear in all copies.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include "ctl/optional.h"
@ -21,12 +22,16 @@
#include "ctl/string.h"
// #include <optional>
// #include <string>
// #define ctl std
int
main()
{
{
Optional<int> x;
ctl::optional<int> x;
if (x)
return 1;
if (x.has_value())
@ -34,7 +39,7 @@ main()
}
{
Optional<int> x(42);
ctl::optional<int> x(42);
if (!x)
return 3;
if (!x.has_value())
@ -44,8 +49,8 @@ main()
}
{
Optional<String> x("hello");
Optional<String> y(x);
ctl::optional<ctl::string> x("hello");
ctl::optional<ctl::string> y(x);
if (!y)
return 6;
if (!y.has_value())
@ -55,8 +60,8 @@ main()
}
{
Optional<String> x("world");
Optional<String> y(std::move(x));
ctl::optional<ctl::string> x("world");
ctl::optional<ctl::string> y(std::move(x));
if (!y)
return 9;
if (!y.has_value())
@ -66,8 +71,8 @@ main()
}
{
Optional<int> x(42);
Optional<int> y;
ctl::optional<int> x(42);
ctl::optional<int> y;
y = x;
if (!y)
return 13;
@ -78,8 +83,8 @@ main()
}
{
Optional<String> x("hello");
Optional<String> y;
ctl::optional<ctl::string> x("hello");
ctl::optional<ctl::string> y;
y = std::move(x);
if (!y)
return 16;
@ -90,7 +95,7 @@ main()
}
{
Optional<int> x(42);
ctl::optional<int> x(42);
x.reset();
if (x)
return 20;
@ -99,7 +104,7 @@ main()
}
{
Optional<String> x;
ctl::optional<ctl::string> x;
x.emplace("hello");
if (!x)
return 22;