Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to std::ranges #147

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/fintamath/functions/IFunctionCRTP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class IFunctionCRTP_ : public IFunction {
bool doAnyArgsMatch(const ArgumentsRefVector &argsVect) const {
using AnyArgsType = typename std::tuple_element_t<0, std::tuple<Args...>>;

return std::all_of(argsVect.begin(), argsVect.end(), [](const auto &arg) {
return std::ranges::all_of(argsVect, [](const auto &arg) {
return is<AnyArgsType>(arg);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/fintamath/expressions/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand Down
11 changes: 5 additions & 6 deletions src/fintamath/expressions/IExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ std::vector<Variable> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/numbers/Rational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() == '-') {
Expand Down
10 changes: 5 additions & 5 deletions src/fintamath/parser/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down