From 61d4c021e43aad51fbfb3da0c371e8a6ae0f74c5 Mon Sep 17 00:00:00 2001 From: fintarin Date: Fri, 22 Sep 2023 14:39:00 +0300 Subject: [PATCH] Fix SonarLint warnings --- include/fintamath/core/MultiMethod.hpp | 6 ++---- include/fintamath/exceptions/Exception.hpp | 2 -- .../exceptions/InvalidInputException.hpp | 16 ++++------------ .../fintamath/exceptions/UndefinedException.hpp | 14 +++----------- include/fintamath/functions/IFunction.hpp | 2 +- include/fintamath/functions/IOperator.hpp | 6 +++--- include/fintamath/functions/other/Factorial.hpp | 2 +- src/fintamath/expressions/Expression.cpp | 2 +- src/fintamath/functions/powers/Root.cpp | 2 +- 9 files changed, 16 insertions(+), 36 deletions(-) diff --git a/include/fintamath/core/MultiMethod.hpp b/include/fintamath/core/MultiMethod.hpp index 809b8e19b..face400d2 100644 --- a/include/fintamath/core/MultiMethod.hpp +++ b/include/fintamath/core/MultiMethod.hpp @@ -31,10 +31,8 @@ class MultiMethod { } Res operator()(const auto &...args) const { - auto it = callbacks.find(CallbackId(args.getType()...)); - - if (it != callbacks.end()) { - return it->second(args...); + if (auto iter = callbacks.find(CallbackId(args.getType()...)); iter != callbacks.end()) { + return iter->second(args...); } return {}; diff --git a/include/fintamath/exceptions/Exception.hpp b/include/fintamath/exceptions/Exception.hpp index e3fcfbcf4..345ce6a57 100644 --- a/include/fintamath/exceptions/Exception.hpp +++ b/include/fintamath/exceptions/Exception.hpp @@ -6,8 +6,6 @@ namespace fintamath { class Exception : public std::exception { public: - ~Exception() override = default; - const char *what() const noexcept override { return "Something went wrong..."; } diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp index 618740cb4..5fbed97c6 100644 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ b/include/fintamath/exceptions/InvalidInputException.hpp @@ -11,9 +11,7 @@ class InvalidInputException : public Exception { public: InvalidInputException() = default; - ~InvalidInputException() override = default; - - InvalidInputException(const std::string &input) { + explicit InvalidInputException(const std::string &input) { content += ": " + input; } @@ -27,9 +25,7 @@ class InvalidInputException : public Exception { class InvalidInputFunctionException : public InvalidInputException { public: - ~InvalidInputFunctionException() override = default; - - InvalidInputFunctionException(const std::string &func, const std::vector &argsVect) { + explicit InvalidInputFunctionException(const std::string &func, const std::vector &argsVect) { content += ": " + func + "("; if (!argsVect.empty()) { @@ -50,9 +46,7 @@ class InvalidInputFunctionException : public InvalidInputException { class InvalidInputBinaryOperatorException : public InvalidInputException { public: - ~InvalidInputBinaryOperatorException() override = default; - - InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -65,9 +59,7 @@ class InvalidInputUnaryOperatorException : public InvalidInputException { }; public: - ~InvalidInputUnaryOperatorException() override = default; - - InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, Type type) { + explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, Type type) { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp index 5f688ac8d..4b4a2fcbc 100644 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ b/include/fintamath/exceptions/UndefinedException.hpp @@ -11,8 +11,6 @@ class UndefinedException : public Exception { public: UndefinedException() = default; - ~UndefinedException() override = default; - explicit UndefinedException(const std::string &input) { content += ": " + input; } @@ -27,9 +25,7 @@ class UndefinedException : public Exception { class UndefinedFunctionException : public UndefinedException { public: - ~UndefinedFunctionException() override = default; - - UndefinedFunctionException(const std::string &func, const std::vector &argsVect) { + explicit UndefinedFunctionException(const std::string &func, const std::vector &argsVect) { content += ": " + func + "("; if (!argsVect.empty()) { @@ -50,9 +46,7 @@ class UndefinedFunctionException : public UndefinedException { class UndefinedBinaryOperatorException : public UndefinedException { public: - ~UndefinedBinaryOperatorException() override = default; - - UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -65,9 +59,7 @@ class UndefinedUnaryOperatorException : public UndefinedException { }; public: - ~UndefinedUnaryOperatorException() override = default; - - UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, Type type) { + explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, Type type) { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/include/fintamath/functions/IFunction.hpp b/include/fintamath/functions/IFunction.hpp index 1dbe48cd8..5bd79f0f8 100644 --- a/include/fintamath/functions/IFunction.hpp +++ b/include/fintamath/functions/IFunction.hpp @@ -77,7 +77,7 @@ class IFunctionCRTP : public IFunction { #undef I_FUNCTION_CRTP public: - IFunctionCRTP(bool isNonExressionEvaluatable = true) : isNonExressionEvaluatableFunc(isNonExressionEvaluatable) { + explicit IFunctionCRTP(bool isNonExressionEvaluatable = true) : isNonExressionEvaluatableFunc(isNonExressionEvaluatable) { if constexpr (IsFunctionTypeAny::value) { type = Type::Any; } diff --git a/include/fintamath/functions/IOperator.hpp b/include/fintamath/functions/IOperator.hpp index d6e56d326..b9dc404a0 100644 --- a/include/fintamath/functions/IOperator.hpp +++ b/include/fintamath/functions/IOperator.hpp @@ -55,9 +55,9 @@ class IOperatorCRTP : public IOperator { #undef I_OPERATOR_CRTP public: - IOperatorCRTP(IOperator::Priority inPriority = IOperator::Priority::Any, - bool isAssociative = false, - bool isNonExressionEvaluatable = true) + explicit IOperatorCRTP(IOperator::Priority inPriority = IOperator::Priority::Any, + bool isAssociative = false, + bool isNonExressionEvaluatable = true) : isNonExressionEvaluatableFunc(isNonExressionEvaluatable), priority(inPriority), isAssociativeOper(isAssociative) { diff --git a/include/fintamath/functions/other/Factorial.hpp b/include/fintamath/functions/other/Factorial.hpp index b33c4a251..e2e8d6b07 100644 --- a/include/fintamath/functions/other/Factorial.hpp +++ b/include/fintamath/functions/other/Factorial.hpp @@ -16,7 +16,7 @@ class Factorial : public IOperatorCRTP { Factorial() : IOperatorCRTP(IOperator::Priority::PostfixUnary) { } - Factorial(size_t inOrder) : Factorial() { + explicit Factorial(size_t inOrder) : Factorial() { setOrder(inOrder); } diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 1637c1904..5b87c72a1 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -314,7 +314,7 @@ void Expression::insertMultiplications(TermsVector &terms) { void Expression::fixOperatorTypes(TermsVector &terms) { bool isFixed = true; - if (auto &term = terms.front(); + if (const auto &term = terms.front(); is(term->value) && !isPrefixOperator(term->value)) { diff --git a/src/fintamath/functions/powers/Root.cpp b/src/fintamath/functions/powers/Root.cpp index 0b8833f69..82a9bd6ce 100644 --- a/src/fintamath/functions/powers/Root.cpp +++ b/src/fintamath/functions/powers/Root.cpp @@ -117,7 +117,7 @@ std::map Root::roots(const Integer &lhs, const Integer &rhs) { rootIter->second *= factor; } else { - rootFactors.emplace(power.denominator(), factor); + rootFactors.try_emplace(power.denominator(), factor); } }