Skip to content

Commit

Permalink
Do not use namespaces stdr, stdv
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Apr 5, 2024
1 parent 93d347d commit 5b686d1
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 23 deletions.
4 changes: 0 additions & 4 deletions include/fintamath/core/CoreUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

#include <concepts>
#include <functional>
#include <ranges>

namespace fintamath {

namespace stdr = std::ranges;
namespace stdv = std::views;

template <typename From, typename To>
concept ConvertibleToAndNotSameAs = std::convertible_to<From, To> && !std::same_as<From, To>;

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 @@ -101,7 +101,7 @@ class IFunctionCRTP_ : public IFunction {
bool doAnyArgsMatch(const ArgumentRefVector &argVect) const {
using AnyArgsType = typename std::tuple_element_t<0, std::tuple<Args...>>;

return stdr::all_of(argVect, [](const auto &arg) {
return std::ranges::all_of(argVect, [](const auto &arg) {
return is<AnyArgsType>(arg);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/core/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TokenVector Tokenizer::tokenize(std::string str) {

void Tokenizer::registerToken(const Token &token) {
auto &tokens = getRegisteredTokens();
tokens.insert(stdr::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) {
tokens.insert(std::ranges::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) {
return lhs.size() > rhs.size();
}),
token);
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ bool Expression::doesArgMatch(const MathObjectClass &expectedType, const Argumen
namespace detail {

std::unique_ptr<IMathObject> makeExpr(const IFunction &func, ArgumentPtrVector args) {
stdr::transform(args, args.begin(), &Expression::compress);
std::ranges::transform(args, args.begin(), &Expression::compress);
Expression::validateFunctionArgs(func, args);

if (const auto strToConstr = Expression::getExpressionMaker().find(func.getClass());
Expand Down
11 changes: 4 additions & 7 deletions src/fintamath/expressions/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool containsIf(const ArgumentPtr &arg, const std::function<bool(const ArgumentP

const ArgumentPtrVector &children = expr->getChildren();

return stdr::any_of(children, [&comp](const auto &child) {
return std::ranges::any_of(children, [&comp](const auto &child) {
bool res = false;

if (containsIf(child, comp)) {
Expand Down Expand Up @@ -226,12 +226,9 @@ std::pair<ArgumentPtr, ArgumentPtr> splitRational(const ArgumentPtr &arg) {
ArgumentPtr negate(const ArgumentPtr &arg) {
if (const auto expr = cast<IExpression>(arg)) {
if (is<Add>(expr->getFunction())) {
auto negChildrenView =
expr->getChildren() |
stdv::transform([](const ArgumentPtr &child) {
return negate(child);
});
return makePolynom(Add{}, ArgumentPtrVector(negChildrenView.begin(), negChildrenView.end())); // TODO: use C++23 stdv::to
ArgumentPtrVector negChildren = expr->getChildren();
std::ranges::transform(negChildren, negChildren.begin(), &negate);
return makePolynom(Add{}, std::move(negChildren));
}

if (is<Mul>(expr->getFunction())) {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/IExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ std::vector<Variable> IExpression::getVariables() const {
}
}

stdr::sort(vars, std::less{}, &Variable::toString);
auto unique = stdr::unique(vars);
std::ranges::sort(vars, std::less{}, &Variable::toString);
auto unique = std::ranges::unique(vars);
vars.erase(unique.begin(), unique.end());

return vars;
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/binary/CompExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ ArgumentPtr CompExpr::rateSimplify(const IFunction &func, const ArgumentPtr &lhs
return {};
}

for (auto &child : stdv::drop(children, 1)) {
for (auto &child : children | std::views::drop(1)) {
child = divExpr(child, rate);
}

Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/binary/DerivativeExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ArgumentPtr DerivativeExpr::exprSimplify(const std::shared_ptr<const IExpression
ArgumentPtr DerivativeExpr::addSimplify(const ArgumentPtrVector &children, const std::shared_ptr<const Variable> &var) {
ArgumentPtrVector newChildren = children;

stdr::transform(newChildren, newChildren.begin(), [&var](const ArgumentPtr &child) {
std::ranges::transform(newChildren, newChildren.begin(), [&var](const ArgumentPtr &child) {
return derivativeExpr(child, var);
});

Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/binary/DivExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ std::pair<ArgumentPtr, ArgumentPtr> DivExpr::mulSumSimplify(const ArgumentPtr &l

ArgumentPtrVector multiplicators;

for (const auto &rhsChild : rhsChildren | stdv::drop(1)) {
for (const auto &rhsChild : rhsChildren | std::views::drop(1)) {
multiplicators.emplace_back(mulExpr(rhsChild, result));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void IPolynomExpression::setChildren(const ArgumentPtrVector &childVect) {
}

void IPolynomExpression::sort() {
stdr::stable_sort(children, [this](const ArgumentPtr &lhs, const ArgumentPtr &rhs) {
std::ranges::stable_sort(children, [this](const ArgumentPtr &lhs, const ArgumentPtr &rhs) {
return compare(lhs, rhs) == std::strong_ordering::greater;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/functions/calculus/Max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace fintamath {
std::unique_ptr<IMathObject> Max::call(const ArgumentRefVector &argVect) const {
std::reference_wrapper res = cast<IComparable>(argVect.front().get());

for (const auto &arg : argVect | stdv::drop(1)) {
for (const auto &arg : argVect | std::views::drop(1)) {
if (is<Complex>(arg)) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/functions/calculus/Min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace fintamath {
std::unique_ptr<IMathObject> Min::call(const ArgumentRefVector &argVect) const {
std::reference_wrapper res = cast<IComparable>(argVect.front().get());

for (const auto &arg : argVect | stdv::drop(1)) {
for (const auto &arg : argVect | std::views::drop(1)) {
if (is<Complex>(arg)) {
return {};
}
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 @@ -27,7 +27,7 @@ Rational::Rational(const std::string &str) {
}

int64_t firstDigitNum = 0;
const int64_t firstDotNum = stdr::distance(str.begin(), stdr::find(str, '.'));
const int64_t firstDotNum = std::ranges::distance(str.begin(), std::ranges::find(str, '.'));

bool isNegative = false;
if (str.front() == '-') {
Expand Down

0 comments on commit 5b686d1

Please sign in to comment.