diff --git a/include/nameof.hpp b/include/nameof.hpp index cff90c1..d32588f 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -148,38 +149,21 @@ class cstring final { constexpr const char* data() const noexcept { return str_; } - constexpr cstring remove_prefix(std::size_t n) const { - return {str_ + n, size_ - n}; - } + constexpr cstring remove_prefix(std::size_t n) const { return {str_ + n, size_ - n}; } - constexpr cstring add_prefix(std::size_t n) const { - return {str_ - n, size_ + n}; - } + constexpr cstring add_prefix(std::size_t n) const { return {str_ - n, size_ + n}; } - constexpr cstring remove_suffix(std::size_t n) const { - return {str_, size_ - n}; - } + constexpr cstring remove_suffix(std::size_t n) const { return {str_, size_ - n}; } - constexpr cstring add_suffix(std::size_t n) const { - return {str_, size_ + n}; - } + constexpr cstring add_suffix(std::size_t n) const { return {str_, size_ + n}; } - constexpr cstring substr(std::size_t pos, std::size_t n) const { - return {str_ + pos, n}; - } + constexpr cstring substr(std::size_t pos, std::size_t n) const { return {str_ + pos, n}; } - int compare(cstring s) const { - auto result = std::char_traits::compare(str_, s.str_, s.size_ < size_ ? s.size_ : size_); - if (result != 0) { + int compare(cstring other) const { + if (const auto result = std::char_traits::compare(str_, other.str_, other.size_ < size_ ? other.size_ : size_)) return result; - } - if (size_ < s.size_) { - return -1; - } - if (size_ > s.size_) { - return 1; - } - return 0; + + return size_ == other.size_ ? 0 : size_ < other.size_ ? -1 : 1; } friend constexpr bool operator==(cstring lhs, cstring rhs) noexcept {