From e420eca2b244c303af51534ab09632045a186b21 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 3 Oct 2024 08:07:05 -0500 Subject: Cleanup from clang-tidy. --- include/fud_c_file.hpp | 8 ++++---- include/fud_directory.hpp | 6 +++--- include/fud_result.hpp | 52 +++++++++++++++++++++++++++++++++++++++-------- include/fud_sqlite.hpp | 8 ++++---- include/fud_string.hpp | 4 ++-- include/fud_utf8.hpp | 4 ++-- 6 files changed, 58 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index 0908841..1c7c304 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -393,13 +393,13 @@ class CBinaryFile : public detail::CFile { CBinaryFile(const CBinaryFile& rhs) = delete; - CBinaryFile(CBinaryFile&& rhs); + CBinaryFile(CBinaryFile&& rhs) noexcept; ~CBinaryFile(); CBinaryFile& operator=(const CBinaryFile& rhs) = delete; - CBinaryFile& operator=(CBinaryFile&& rhs); + CBinaryFile& operator=(CBinaryFile&& rhs) noexcept; private: String m_filename; @@ -419,13 +419,13 @@ class CTextFile : public detail::CFile { CTextFile(const CTextFile& rhs) = delete; - CTextFile(CTextFile&& rhs); + CTextFile(CTextFile&& rhs) noexcept; ~CTextFile(); CTextFile& operator=(const CTextFile& rhs) = delete; - CTextFile& operator=(CTextFile&& rhs); + CTextFile& operator=(CTextFile&& rhs) noexcept; private: String m_filename; diff --git a/include/fud_directory.hpp b/include/fud_directory.hpp index cd3576e..ca94528 100644 --- a/include/fud_directory.hpp +++ b/include/fud_directory.hpp @@ -91,12 +91,12 @@ struct DirectoryEntry { class Directory { public: - explicit Directory(String name); + explicit Directory(const String& name); Directory(const Directory& rhs) = delete; - Directory(Directory&& rhs); + Directory(Directory&& rhs) noexcept; ~Directory(); Directory& operator=(const Directory& rhs) = delete; - Directory& operator=(Directory&& rhs) = delete; + Directory& operator=(Directory&& rhs) noexcept = delete; constexpr const String& name() const { return m_name; diff --git a/include/fud_result.hpp b/include/fud_result.hpp index 9b96399..076af21 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -23,6 +23,30 @@ namespace fud { +namespace detail { +template +class CopyMove { + public: + explicit constexpr CopyMove(T value) : m_value{std::move(value)} + { + } + + constexpr T&& take() + { + return std::move(m_value); + } + + constexpr T copy() const + { + return m_value; + } + + private: + T m_value; +}; + +} // namespace detail + /** \brief A result type which contains either a T on success or an E on error. */ template class [[nodiscard]] Result { @@ -58,35 +82,45 @@ class [[nodiscard]] Result { return (m_value.index() == 1); } - T getOkay() + [[nodiscard]] T getOkay() const + { + return std::get>(m_value).copy(); + } + + [[nodiscard]] E getError() const + { + return std::get>(m_value).copy(); + } + + [[nodiscard]] T&& getOkay() { - return std::get(m_value); + return std::get>(m_value).take(); } - E getError() + [[nodiscard]] E&& getError() { - return std::get(m_value); + return std::get>(m_value).take(); } private: explicit Result() : m_value() { } - explicit Result(const T& value) : m_value(value) + explicit Result(const T& value) : m_value{detail::CopyMove{value}} { } - explicit Result(const E& value) : m_value(value) + explicit Result(const E& value) : m_value{detail::CopyMove{value}} { } - explicit Result(T&& value) : m_value(std::move(value)) + explicit Result(T&& value) : m_value{detail::CopyMove{std::move(value)}} { } - explicit Result(E&& value) : m_value(std::move(value)) + explicit Result(E&& value) : m_value{detail::CopyMove{std::move(value)}} { } - std::variant m_value; + std::variant, detail::CopyMove> m_value; }; } // namespace fud diff --git a/include/fud_sqlite.hpp b/include/fud_sqlite.hpp index 555e487..d879ed0 100644 --- a/include/fud_sqlite.hpp +++ b/include/fud_sqlite.hpp @@ -42,13 +42,13 @@ class SqliteDb { SqliteDb(const SqliteDb&) = delete; - SqliteDb(SqliteDb&& rhs); + SqliteDb(SqliteDb&& rhs) noexcept; ~SqliteDb(); SqliteDb& operator=(const SqliteDb&) = delete; - SqliteDb& operator=(SqliteDb&& rhs); + SqliteDb& operator=(SqliteDb&& rhs) noexcept; bool valid() const; @@ -99,13 +99,13 @@ class SqliteStatement { SqliteStatement(const SqliteStatement&) = delete; - SqliteStatement(SqliteStatement&& rhs); + SqliteStatement(SqliteStatement&& rhs) noexcept; ~SqliteStatement(); SqliteStatement& operator=(const SqliteStatement&) = delete; - SqliteStatement& operator=(SqliteStatement&& rhs) = delete; + SqliteStatement& operator=(SqliteStatement&& rhs) noexcept = delete; bool valid() const; diff --git a/include/fud_string.hpp b/include/fud_string.hpp index 1a38d43..1939c7d 100644 --- a/include/fud_string.hpp +++ b/include/fud_string.hpp @@ -38,11 +38,11 @@ class String { explicit String(const utf8* cString); explicit String(const char* cString); String(const String& rhs); - String(String&& rhs); + String(String&& rhs) noexcept; ~String(); String& operator=(const String& rhs); - String& operator=(String&& rhs); + String& operator=(String&& rhs) noexcept; [[nodiscard]] constexpr size_t length() const { diff --git a/include/fud_utf8.hpp b/include/fud_utf8.hpp index 5b84a3a..058e4f9 100644 --- a/include/fud_utf8.hpp +++ b/include/fud_utf8.hpp @@ -251,8 +251,8 @@ struct FudUtf8 { static constexpr Ascii invalidAsciiCode{Ascii{0xFF}}; static FudUtf8 fromString(const String& fudString, size_t index) noexcept; - static FudUtf8 fromStringView(StringView&& view, size_t index) noexcept; - static FudUtf8 fromStringView(const StringView& view, size_t index) noexcept; + static FudUtf8 fromStringView(StringView view, size_t index) noexcept; + // static FudUtf8 fromStringView(const StringView& view, size_t index) noexcept; static constexpr FudUtf8 makeUtf8(const Array& data) { -- cgit v1.2.3