diff --git a/include/frozen/string.h b/include/frozen/string.h index 354ed9c..6d29d7e 100644 --- a/include/frozen/string.h +++ b/include/frozen/string.h @@ -51,18 +51,40 @@ class basic_string { constexpr basic_string(chr_t const *data, std::size_t size) : data_(data), size_(size) {} -#ifdef FROZEN_LETITGO_HAS_STRING_VIEW - constexpr basic_string(std::basic_string_view data) - : data_(data.data()), size_(data.size()) {} -#endif - constexpr basic_string(const basic_string &) noexcept = default; constexpr basic_string &operator=(const basic_string &) noexcept = default; + constexpr std::size_t length() const { return size_; } constexpr std::size_t size() const { return size_; } constexpr chr_t operator[](std::size_t i) const { return data_[i]; } +#ifdef FROZEN_LETITGO_HAS_STRING_VIEW + constexpr basic_string(std::basic_string_view data) + : data_(data.data()), size_(data.size()) {} + + constexpr operator std::basic_string_view() const { + return std::basic_string_view(data_, size_); + } + + constexpr bool operator==(std::basic_string_view other) const { + return (std::basic_string_view(data_, size_) == other); + } + + constexpr bool operator<(const std::basic_string_view &other) const { + return (std::basic_string_view(data_, size_) < other); + } + + constexpr bool operator==(basic_string other) const { + return (std::basic_string_view(data_, size_) == std::basic_string_view(other.data_, other.size_)); + } + + constexpr bool operator<(const basic_string &other) const { + return (std::basic_string_view(data_, size_) < std::basic_string_view(other.data_, other.size_)); + } + +#else + constexpr bool operator==(basic_string other) const { if (size_ != other.size_) return false; @@ -86,6 +108,8 @@ class basic_string { return size() < other.size(); } +#endif + friend constexpr bool operator>(const basic_string& lhs, const basic_string& rhs) { return rhs < lhs; }