diff --git a/docs/error/index.rst b/docs/error/index.rst index 0362761..87e9c8d 100644 --- a/docs/error/index.rst +++ b/docs/error/index.rst @@ -13,10 +13,6 @@ API Docs .. doxygenstruct:: error::Error :members: -.. doxygenfunction:: error::operator== - -.. doxygenfunction:: error::operator!= - License ------- diff --git a/error/.clang-format b/error/.clang-format index f6cb8ad..880cdc7 100644 --- a/error/.clang-format +++ b/error/.clang-format @@ -1 +1,2 @@ BasedOnStyle: Google +ColumnLimit: 0 diff --git a/error/include/error/error.hpp b/error/include/error/error.hpp index f2ef001..cc85fea 100644 --- a/error/include/error/error.hpp +++ b/error/include/error/error.hpp @@ -33,6 +33,40 @@ struct Error { * @endcode */ friend std::ostream& operator<<(std::ostream& os, const error::Error& err); + + /** + * @brief Checks if two error objects are equal. + * @param lhs The left-hand side error object. + * @param rhs The right-hand side error object. + * @return True if equal, false otherwise. + * + * This operator allows the comparison of two error objects using the == operator. + * + * @code{.cpp} + * const auto err = error::make("unknown error"); + * const auto other_err = err; + * + * assert(err == other_err); + * @endcode + */ + friend bool operator==(const Error& lhs, const Error& rhs); + + /** + * @brief Checks if two error objects are not equal. + * @param lhs The left-hand side error object. + * @param rhs The right-hand side error object. + * @return True if not equal, false otherwise. + * + * This operator allows the comparison of two error objects using the != operator. + * + * @code{.cpp} + * const auto err = error::make("unknown error"); + * const auto other_err = error::make("other error"); + * + * assert(err != other_err); + * @endcode + */ + friend bool operator!=(const Error& lhs, const Error& rhs); }; /** @@ -54,22 +88,6 @@ Error format(fmt::format_string fmt, T&&... args) { return error::make(fmt::format(fmt, std::forward(args)...)); } -/** - * @brief Checks if two error objects are equal. - * @param lhs The left-hand side error object. - * @param rhs The right-hand side error object. - * @return True if equal, false otherwise. - */ -bool operator==(const Error& lhs, const Error& rhs); - -/** - * @brief Checks if two error objects are not equal. - * @param lhs The left-hand side error object. - * @param rhs The right-hand side error object. - * @return True if not equal, false otherwise. - */ -bool operator!=(const Error& lhs, const Error& rhs); - } // namespace error template <> diff --git a/error/src/error.cpp b/error/src/error.cpp index 04a9c7b..49d28ce 100644 --- a/error/src/error.cpp +++ b/error/src/error.cpp @@ -6,8 +6,6 @@ std::ostream& operator<<(std::ostream& os, const error::Error& err) { return os << "error: " << err.message; } -Error make(const std::string& msg) { return Error{.message = msg}; } - bool operator==(const Error& lhs, const Error& rhs) { return lhs.message == rhs.message; } @@ -16,6 +14,8 @@ bool operator!=(const Error& lhs, const Error& rhs) { return lhs.message != rhs.message; } +Error make(const std::string& msg) { return Error{.message = msg}; } + } // namespace error namespace fmt {