summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-03 08:07:05 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-03 08:07:05 -0500
commite420eca2b244c303af51534ab09632045a186b21 (patch)
treeba4ec2d6863b716672f35898266516b58c727aa9 /include
parent97bbafb762defc01abc38834b70a7e8f20d654f5 (diff)
Cleanup from clang-tidy.
Diffstat (limited to 'include')
-rw-r--r--include/fud_c_file.hpp8
-rw-r--r--include/fud_directory.hpp6
-rw-r--r--include/fud_result.hpp52
-rw-r--r--include/fud_sqlite.hpp8
-rw-r--r--include/fud_string.hpp4
-rw-r--r--include/fud_utf8.hpp4
6 files changed, 58 insertions, 24 deletions
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> {
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> {
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 <typename T>
+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 <typename T, typename E>
class [[nodiscard]] Result {
@@ -58,35 +82,45 @@ class [[nodiscard]] Result {
return (m_value.index() == 1);
}
- T getOkay()
+ [[nodiscard]] T getOkay() const
+ {
+ return std::get<detail::CopyMove<T>>(m_value).copy();
+ }
+
+ [[nodiscard]] E getError() const
+ {
+ return std::get<detail::CopyMove<E>>(m_value).copy();
+ }
+
+ [[nodiscard]] T&& getOkay()
{
- return std::get<T>(m_value);
+ return std::get<detail::CopyMove<T>>(m_value).take();
}
- E getError()
+ [[nodiscard]] E&& getError()
{
- return std::get<E>(m_value);
+ return std::get<detail::CopyMove<E>>(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<T>{value}}
{
}
- explicit Result(const E& value) : m_value(value)
+ explicit Result(const E& value) : m_value{detail::CopyMove<E>{value}}
{
}
- explicit Result(T&& value) : m_value(std::move(value))
+ explicit Result(T&& value) : m_value{detail::CopyMove<T>{std::move(value)}}
{
}
- explicit Result(E&& value) : m_value(std::move(value))
+ explicit Result(E&& value) : m_value{detail::CopyMove<E>{std::move(value)}}
{
}
- std::variant<T, E> m_value;
+ std::variant<detail::CopyMove<T>, detail::CopyMove<E>> 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<utf8, 4>& data)
{