From 71e3dba69a12f79f577e9ee0b6792d9fbad853c8 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 4 Sep 2020 22:48:36 +0200 Subject: [PATCH] symbol_text refactored --- src/include/units/symbol_text.h | 69 ++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/src/include/units/symbol_text.h b/src/include/units/symbol_text.h index 9ade00d2..6114d11b 100644 --- a/src/include/units/symbol_text.h +++ b/src/include/units/symbol_text.h @@ -1,21 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + #pragma once #include #include #include +#if COMP_GCC >= 10 +#include +#endif + namespace units { namespace detail { constexpr void validate_ascii_char([[maybe_unused]] char c) noexcept { Expects((c & 0x80) == 0); } -template -constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[P + 1]) noexcept +template +constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) noexcept { #ifndef NDEBUG - if constexpr (P != 0) - for (size_t i = 0; i < P; ++i) + if constexpr (N != 0) + for (size_t i = 0; i < N; ++i) validate_ascii_char(s[i]); #endif } @@ -39,10 +65,10 @@ struct basic_symbol_text { basic_fixed_string standard_; basic_fixed_string ascii_; - constexpr basic_symbol_text(StandardCharT s) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_char(s); } + constexpr basic_symbol_text(char s) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_char(s); } constexpr basic_symbol_text(StandardCharT s, char a) noexcept: standard_(s), ascii_(a) { detail::validate_ascii_char(a); } - constexpr basic_symbol_text(const StandardCharT (&s)[N + 1]) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_string(s); } - constexpr basic_symbol_text(const basic_fixed_string& s) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_string(s.data_); } + constexpr basic_symbol_text(const char (&s)[N + 1]) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_string(s); } + constexpr basic_symbol_text(const basic_fixed_string& s) noexcept: standard_(s), ascii_(s) { detail::validate_ascii_string(s.data_); } constexpr basic_symbol_text(const StandardCharT (&s)[N + 1], const char (&a)[M + 1]) noexcept: standard_(s), ascii_(a) { detail::validate_ascii_string(a); } constexpr basic_symbol_text(const basic_fixed_string& s, const basic_fixed_string& a) noexcept: standard_(s), ascii_(a) { detail::validate_ascii_string(a.data_); } @@ -56,7 +82,7 @@ struct basic_symbol_text { const basic_symbol_text& lhs, const basic_symbol_text& rhs) noexcept { return basic_symbol_text( - lhs.standard_ + rhs.standard_, lhs.ascii_ + rhs.ascii_); + lhs.standard() + rhs.standard(), lhs.ascii() + rhs.ascii()); } template @@ -99,21 +125,21 @@ struct basic_symbol_text { return basic_symbol_text(lhs) + rhs; } -#if __GNUC__ >= 10 +#if COMP_GCC >= 10 template [[nodiscard]] friend constexpr auto operator<=>(const basic_symbol_text& lhs, const basic_symbol_text& rhs) noexcept { - if (const auto cmp = lhs.standard_ <=> rhs.standard_; cmp != 0) return cmp; - return lhs.ascii_ <=> rhs.ascii_; + if (const auto cmp = lhs.standard() <=> rhs.standard(); cmp != 0) return cmp; + return lhs.ascii() <=> rhs.ascii(); } template [[nodiscard]] friend constexpr bool operator==(const basic_symbol_text& lhs, const basic_symbol_text& rhs) noexcept { - return lhs.standard_ == rhs.standard_ && lhs.ascii_ == rhs.ascii_; + return lhs.standard() == rhs.standard() && lhs.ascii() == rhs.ascii(); } #else @@ -124,7 +150,7 @@ struct basic_symbol_text { [[nodiscard]] constexpr friend bool operator==(const basic_symbol_text& lhs, const basic_symbol_text& rhs) noexcept { - return lhs.standard_ == rhs.standard_; + return lhs.standard() == rhs.standard(); } template @@ -137,7 +163,7 @@ struct basic_symbol_text { [[nodiscard]] constexpr friend bool operator==(const basic_symbol_text& lhs, const basic_fixed_string& rhs) noexcept { - return lhs.standard_ == rhs; + return lhs.standard() == rhs; } [[nodiscard]] constexpr friend bool operator!=(const basic_symbol_text& lhs, @@ -163,7 +189,7 @@ struct basic_symbol_text { [[nodiscard]] constexpr friend bool operator==(const basic_symbol_text& lhs, const StandardCharT (&rhs)[N + 1]) noexcept { - return lhs.standard_ == rhs; + return lhs.standard() == rhs; } [[nodiscard]] constexpr friend bool operator!=(const basic_symbol_text& lhs, @@ -189,7 +215,7 @@ struct basic_symbol_text { [[nodiscard]] constexpr friend bool operator==(const basic_symbol_text& lhs, StandardCharT rhs) noexcept { - return lhs.standard_ == rhs; + return lhs.standard() == rhs; } [[nodiscard]] constexpr friend bool operator!=(const basic_symbol_text& lhs, @@ -216,28 +242,28 @@ struct basic_symbol_text { [[nodiscard]] constexpr friend bool operator<(const basic_symbol_text& lhs, const basic_symbol_text& rhs) noexcept { - return lhs.standard_ < rhs.standard_; + return lhs.standard() < rhs.standard(); } template [[nodiscard]] constexpr friend bool operator<(const basic_symbol_text& lhs, const basic_fixed_string& rhs) noexcept { - return lhs.standard_ < rhs; + return lhs.standard() < rhs; } template [[nodiscard]] constexpr friend bool operator<(const basic_symbol_text& lhs, const StandardCharT2 (&rhs)[N2]) noexcept { - return lhs.standard_ < basic_fixed_string(rhs); + return lhs.standard() < basic_fixed_string(rhs); } template [[nodiscard]] constexpr friend bool operator<(const basic_symbol_text& lhs, StandardCharT2 rhs) noexcept { - return lhs.standard_ < basic_fixed_string(rhs); + return lhs.standard() < basic_fixed_string(rhs); } template @@ -344,7 +370,6 @@ basic_symbol_text(const StandardCharT (&)[N], const char (&)[M]) -> basic_symbol template basic_symbol_text(const basic_fixed_string&, - const basic_fixed_string&) --> basic_symbol_text; + const basic_fixed_string&) -> basic_symbol_text; } // namespace units