summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-05 08:33:39 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-05 08:33:39 -0500
commit79620980ea3880f6512a35b9d688a60a02ff8b98 (patch)
treeb4ab3dfc656b88989f3e4234e9c476c295c176ed /include
parentb50980ad70684530d55b7adf20de6047ebf53ba2 (diff)
Formatting changes. Refactoring out detail::CopyMove from Result.
Diffstat (limited to 'include')
-rw-r--r--include/fud_assert.hpp12
-rw-r--r--include/fud_result.hpp45
-rw-r--r--include/libfud.hpp3
3 files changed, 22 insertions, 38 deletions
diff --git a/include/fud_assert.hpp b/include/fud_assert.hpp
index fd861ea..8caf751 100644
--- a/include/fud_assert.hpp
+++ b/include/fud_assert.hpp
@@ -20,11 +20,15 @@
namespace fud {
-void assertFail(const char* assertion, const char* file, unsigned int line, const char* function) noexcept(false)
- __attribute__((__noreturn__));
+// clang-format off
+[[noreturn]] void assertFail(
+ const char* assertion,
+ const char* file,
+ unsigned int line,
+ const char* function) noexcept(false);
+// clang-format on
-#define fudAssert(expr) \
- ((expr) ? static_cast<void>(0) : assertFail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
+#define fudAssert(expr) ((expr) ? static_cast<void>(0) : assertFail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
} // namespace fud
diff --git a/include/fud_result.hpp b/include/fud_result.hpp
index 076af21..74954df 100644
--- a/include/fud_result.hpp
+++ b/include/fud_result.hpp
@@ -23,30 +23,6 @@
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 {
@@ -84,43 +60,46 @@ class [[nodiscard]] Result {
[[nodiscard]] T getOkay() const
{
- return std::get<detail::CopyMove<T>>(m_value).copy();
+ return std::get<T>(m_value);
}
[[nodiscard]] E getError() const
{
- return std::get<detail::CopyMove<E>>(m_value).copy();
+ return std::get<E>(m_value);
}
[[nodiscard]] T&& getOkay()
{
- return std::get<detail::CopyMove<T>>(m_value).take();
+ return std::move(std::get<T>(m_value));
}
[[nodiscard]] E&& getError()
{
- return std::get<detail::CopyMove<E>>(m_value).take();
+ return std::move(std::get<E>(m_value));
}
private:
explicit Result() : m_value()
{
}
- explicit Result(const T& value) : m_value{detail::CopyMove<T>{value}}
+
+ explicit Result(const T& value) : m_value{value}
{
}
- explicit Result(const E& value) : m_value{detail::CopyMove<E>{value}}
+
+ explicit Result(const E& value) : m_value{value}
{
}
- explicit Result(T&& value) : m_value{detail::CopyMove<T>{std::move(value)}}
+ explicit Result(T&& value) : m_value{std::move(value)}
{
}
- explicit Result(E&& value) : m_value{detail::CopyMove<E>{std::move(value)}}
+
+ explicit Result(E&& value) : m_value{std::move(value)}
{
}
- std::variant<detail::CopyMove<T>, detail::CopyMove<E>> m_value;
+ std::variant<T, E> m_value;
};
} // namespace fud
diff --git a/include/libfud.hpp b/include/libfud.hpp
index 70165b3..c670ed4 100644
--- a/include/libfud.hpp
+++ b/include/libfud.hpp
@@ -18,10 +18,10 @@
#ifndef LIBFUD_HPP
#define LIBFUD_HPP
+#include "fud_array.hpp"
#include "fud_result.hpp"
#include "fud_status.hpp"
#include "fud_string.hpp"
-#include "fud_array.hpp"
#include <cstdint>
@@ -36,6 +36,7 @@ struct FUD {
Array<char, GIT_REV_CHARS> revision;
};
+/** \brief Get the version of FUD including git revision. */
FUD fud();
/**