diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13b94046c..54df757e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,8 +23,9 @@ jobs: config: - { name: Ubuntu GCC, os: ubuntu-latest, cc: gcc, cxx: g++ } - { name: Ubuntu Clang, os: ubuntu-latest, cc: clang, cxx: clang++ } - - { name: macOS GCC, os: macOS-latest, cc: gcc, cxx: g++ } - - { name: macOS Clang, os: macOS-latest, cc: clang, cxx: clang++ } + # TODO: remove version specifiers after macOS-latest upgrades to version 13 + - { name: macOS GCC, os: macOS-13, cc: gcc, cxx: g++ } + - { name: macOS Clang, os: macOS-13, cc: clang, cxx: clang++ } - { name: Windows GCC, os: windows-latest, cc: gcc, cxx: g++ } - { name: Windows Clang, os: windows-latest, cc: clang, cxx: clang++ } - { name: Windows MSVC, os: windows-latest, cc: msvc, cxx: msvc } @@ -33,6 +34,13 @@ jobs: - name: Checkout uses: actions/checkout@v3 + # TODO: remove this step after the default Clang is updated to version 16 + - name: Install LLVM and Clang + if: matrix.config.os == 'ubuntu-latest' + uses: KyleMayes/install-llvm-action@v1 + with: + version: "16.0" + - name: Configure CMake working-directory: ${{github.workspace}} run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dfintamath_build_tests=ON -Dfintamath_build_shared=ON -Dfintamath_warnings_as_errors=ON diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bf671d5f3..fc89d5292 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,6 +28,12 @@ jobs: sudo apt-get update sudo apt-get install llvm lcov + # TODO: remove this step after the default Clang is updated to version 16 + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "16.0" + - name: Configure CMake working-directory: ${{github.workspace}} run: cmake -Bbuild -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dfintamath_build_tests=ON -Dfintamath_enable_coverage=ON diff --git a/README.md b/README.md index c8b36a66e..dbe5a1f73 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,9 @@ Fintamath is an algebra & analysis library written in pure C++. * CMake 3.5 or higher * C++ compilers: * GCC 11 or higher - * Clang 14 or higher - * MSVC 17 or higher + * Clang 16 or higher + * MSVC 19.30 or higher + * Apple Clang 14.0.3 or higher * Operating systems: * Linux * Windows diff --git a/include/fintamath/functions/IFunctionCRTP.hpp b/include/fintamath/functions/IFunctionCRTP.hpp index fa66faf55..6acde9243 100644 --- a/include/fintamath/functions/IFunctionCRTP.hpp +++ b/include/fintamath/functions/IFunctionCRTP.hpp @@ -95,7 +95,7 @@ class IFunctionCRTP_ : public IFunction { bool doAnyArgsMatch(const ArgumentsRefVector &argsVect) const { using AnyArgsType = typename std::tuple_element_t<0, std::tuple>; - return std::all_of(argsVect.begin(), argsVect.end(), [](const auto &arg) { + return std::ranges::all_of(argsVect, [](const auto &arg) { return is(arg); }); } diff --git a/src/fintamath/expressions/ExpressionUtils.cpp b/src/fintamath/expressions/ExpressionUtils.cpp index dd3802a3f..0a5ef2e5e 100644 --- a/src/fintamath/expressions/ExpressionUtils.cpp +++ b/src/fintamath/expressions/ExpressionUtils.cpp @@ -123,7 +123,7 @@ bool hasVariable(const ArgumentPtr &arg) { ArgumentsPtrVector children = expr->getChildren(); - return std::any_of(children.begin(), children.end(), [](const auto &child) { + return std::ranges::any_of(children, [](const auto &child) { bool res = false; if (hasVariable(child)) { @@ -146,7 +146,7 @@ bool hasVariable(const ArgumentPtr &arg, const Variable &var) { ArgumentsPtrVector children = expr->getChildren(); - return std::any_of(children.begin(), children.end(), [&var](const auto &child) { + return std::ranges::any_of(children, [&var](const auto &child) { bool res = false; if (hasVariable(child, var)) { @@ -169,7 +169,7 @@ bool hasInfinity(const ArgumentPtr &arg) { ArgumentsPtrVector children = expr->getChildren(); - return std::any_of(children.begin(), children.end(), [](const auto &child) { + return std::ranges::any_of(children, [](const auto &child) { bool res = false; if (hasInfinity(child)) { @@ -192,7 +192,7 @@ bool hasComplex(const ArgumentPtr &arg) { ArgumentsPtrVector children = expr->getChildren(); - return std::any_of(children.begin(), children.end(), [](const auto &child) { + return std::ranges::any_of(children, [](const auto &child) { bool res = false; if (hasComplex(child)) { diff --git a/src/fintamath/expressions/IExpression.cpp b/src/fintamath/expressions/IExpression.cpp index 6aff96d1b..1d68c46bd 100644 --- a/src/fintamath/expressions/IExpression.cpp +++ b/src/fintamath/expressions/IExpression.cpp @@ -25,12 +25,11 @@ std::vector IExpression::getVariables() const { } } - // TODO! use more efficient algorithm - vars.erase(std::unique(vars.begin(), vars.end(), - [](const Variable &lhs, const Variable &rhs) { - return lhs == rhs; - }), - vars.end()); + std::ranges::sort(vars, [](const Variable &lhs, const Variable &rhs) { + return lhs.toString() < rhs.toString(); + }); + auto unique = std::ranges::unique(vars); + vars.erase(unique.begin(), unique.end()); return vars; } diff --git a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp index 48659052e..63ce9d6b6 100644 --- a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp +++ b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp @@ -202,7 +202,7 @@ void IPolynomExpression::setChildren(const ArgumentsPtrVector &childVect) { } void IPolynomExpression::sort() { - std::stable_sort(children.begin(), children.end(), [this](const ArgumentPtr &lhs, const ArgumentPtr &rhs) { + std::ranges::stable_sort(children, [this](const ArgumentPtr &lhs, const ArgumentPtr &rhs) { return comparator(lhs, rhs) < 0; }); } diff --git a/src/fintamath/numbers/Rational.cpp b/src/fintamath/numbers/Rational.cpp index 74fe6ee19..fc549db61 100644 --- a/src/fintamath/numbers/Rational.cpp +++ b/src/fintamath/numbers/Rational.cpp @@ -16,7 +16,7 @@ Rational::Rational(const std::string &str) { } int64_t firstDigitNum = 0; - int64_t firstDotNum = std::distance(str.begin(), std::find(str.begin(), str.end(), '.')); + int64_t firstDotNum = std::ranges::distance(str.begin(), std::ranges::find(str, '.')); bool isNegative = false; if (str.front() == '-') { diff --git a/src/fintamath/parser/Tokenizer.cpp b/src/fintamath/parser/Tokenizer.cpp index 5aa08eb38..7ef9eef95 100644 --- a/src/fintamath/parser/Tokenizer.cpp +++ b/src/fintamath/parser/Tokenizer.cpp @@ -34,11 +34,11 @@ TokenVector Tokenizer::tokenize(std::string str) { } void Tokenizer::registerToken(const Token &token) { - // TODO: use more efficient algorithm to emplace - getRegisteredTokens().emplace_back(token); - std::sort(getRegisteredTokens().begin(), getRegisteredTokens().end(), [](const Token &a, const Token &b) { - return a.length() > b.length(); - }); + auto &tokens = getRegisteredTokens(); + tokens.insert(std::ranges::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) { + return lhs.length() > rhs.length(); + }), + token); } bool Tokenizer::appendToken(TokenVector &tokens, Token &token, bool shouldSplit) {