From 1aa1b1f743bb63395f79ba03e206430b88f6d7ba Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 24 Dec 2023 21:47:37 +0700 Subject: [PATCH] feat: remove equality and inequality operators in `Error` class --- include/errors/error.hpp | 34 ---------------------------------- src/error.cpp | 8 -------- test/error_test.cpp | 10 ---------- 3 files changed, 52 deletions(-) diff --git a/include/errors/error.hpp b/include/errors/error.hpp index 26628b3..742f5f1 100644 --- a/include/errors/error.hpp +++ b/include/errors/error.hpp @@ -50,40 +50,6 @@ class Error { * @endcode */ friend std::ostream& operator<<(std::ostream& os, const errors::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 = errors::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 = errors::make("unknown error"); - * const auto other_err = errors::make("other error"); - * - * assert(err != other_err); - * @endcode - */ - friend bool operator!=(const Error& lhs, const Error& rhs); }; /** diff --git a/src/error.cpp b/src/error.cpp index 0e111fd..02c0a5e 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -13,14 +13,6 @@ std::ostream& operator<<(std::ostream& os, const errors::Error& err) { return os << "error: " << err.message(); } -bool operator==(const Error& lhs, const Error& rhs) { - return lhs.message() == rhs.message(); -} - -bool operator!=(const Error& lhs, const Error& rhs) { - return lhs.message() != rhs.message(); -} - Error make(const std::string& msg) { return Error(std::make_shared(msg)); } diff --git a/test/error_test.cpp b/test/error_test.cpp index bc24dbd..589e8ba 100644 --- a/test/error_test.cpp +++ b/test/error_test.cpp @@ -15,16 +15,6 @@ TEST_CASE("Error Construction With Formatting") { REQUIRE(err.message() == "HTTP error 404"); } -TEST_CASE("Error Comparison") { - const auto err = errors::make("unknown error"); - const auto err_copy = err; - CHECK(err == err_copy); - CHECK_FALSE(err != err_copy); - const auto other_err = errors::make("other error"); - CHECK_FALSE(err == other_err); - CHECK(err != other_err); -} - TEST_CASE("Error Printing") { const auto err = errors::make("unknown error");