diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_assert.hpp | 12 | ||||
-rw-r--r-- | include/fud_result.hpp | 45 | ||||
-rw-r--r-- | include/libfud.hpp | 3 |
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(); /** |