From fad9240eedd5624235d557ec5da926b739c4b46d Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Thu, 13 Mar 2025 12:16:30 +0100 Subject: [PATCH 1/2] Use C++20 --- CMakeLists.txt | 2 +- cmake/clang-tools.cmake | 2 +- doc/cpp_installation.rst | 2 +- include/amici/forwardproblem.h | 7 ++-- matlab/@amimodel/compileAndLinkModel.m | 4 +- src/amici.cpp | 4 +- src/edata.cpp | 23 ++++-------- src/forwardproblem.cpp | 21 +++++------ src/hdf5.cpp | 7 ++-- src/model.cpp | 52 +++++++++++--------------- src/model_dae.cpp | 2 +- src/model_ode.cpp | 2 +- src/rdata.cpp | 11 +++--- src/solver.cpp | 4 +- src/splinefunctions.cpp | 6 +-- src/steadystateproblem.cpp | 8 ++-- src/sundials_matrix_wrapper.cpp | 7 ++-- src/vector.cpp | 8 ++-- 18 files changed, 72 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 341bb29dd2..1f673c7686 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Compiler flags diff --git a/cmake/clang-tools.cmake b/cmake/clang-tools.cmake index 2a78393802..1fcfd760da 100644 --- a/cmake/clang-tools.cmake +++ b/cmake/clang-tools.cmake @@ -29,7 +29,7 @@ if(CLANG_TIDY) clang-tidy COMMAND sh -c - "${CLANG_TIDY} ${ALL_CXX_SOURCE_FILES} -- -std=c++17 -I${CMAKE_SOURCE_DIR}" + "${CLANG_TIDY} ${ALL_CXX_SOURCE_FILES} -- -std=c++20 -I${CMAKE_SOURCE_DIR}" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) else() message(STATUS "clang-tidy was not found") diff --git a/doc/cpp_installation.rst b/doc/cpp_installation.rst index 7e464122b7..00d896394f 100644 --- a/doc/cpp_installation.rst +++ b/doc/cpp_installation.rst @@ -15,7 +15,7 @@ The following section describes building the AMICI C++ library: Prerequisites: * CBLAS compatible BLAS library -* a C++17 compatible compiler +* a C++20 compatible compiler * a C compiler * Optional: diff --git a/include/amici/forwardproblem.h b/include/amici/forwardproblem.h index cad434a3e1..db1cce5a8a 100644 --- a/include/amici/forwardproblem.h +++ b/include/amici/forwardproblem.h @@ -456,8 +456,9 @@ class FinalStateStorer : public ContextManager { auto final_time = fwd_->getFinalTime(); auto const timepoints = fwd_->model->getTimepoints(); if (!fwd_->timepoint_states_.count(final_time) - && std::find(timepoints.cbegin(), timepoints.cend(), final_time) - != timepoints.cend()) { + && std::find( + timepoints.cbegin(), timepoints.cend(), final_time + ) != timepoints.cend()) { fwd_->timepoint_states_[final_time] = fwd_->final_state_; } } catch (std::exception const&) { @@ -469,7 +470,7 @@ class FinalStateStorer : public ContextManager { // `fwd_->{final_state_,timepoint_states_}` won't be set, // and we assume that they are either not accessed anymore, or // that there is appropriate error handling in place. - if(!std::uncaught_exceptions()) { + if (!std::uncaught_exceptions()) { throw; } } diff --git a/matlab/@amimodel/compileAndLinkModel.m b/matlab/@amimodel/compileAndLinkModel.m index c75f575152..b3549aa90c 100644 --- a/matlab/@amimodel/compileAndLinkModel.m +++ b/matlab/@amimodel/compileAndLinkModel.m @@ -34,9 +34,9 @@ function compileAndLinkModel(modelname, modelSourceFolder, coptim, debug, funs, end % compile flags - COPT = ['COPTIMFLAGS=''' coptim ' -DNDEBUG'' CXXFLAGS=''$CXXFLAGS -std=c++17''']; + COPT = ['COPTIMFLAGS=''' coptim ' -DNDEBUG'' CXXFLAGS=''$CXXFLAGS -std=c++20''']; if(debug) - DEBUG = ' -g CXXFLAGS=''$CXXFLAGS -Wall -std=c++17 -Wno-unused-function -Wno-unused-variable'' '; + DEBUG = ' -g CXXFLAGS=''$CXXFLAGS -Wall -std=c++20 -Wno-unused-function -Wno-unused-variable'' '; COPT = ''; % no optimization with debug flags! else DEBUG = ''; diff --git a/src/amici.cpp b/src/amici.cpp index 8312200e0b..078c270537 100644 --- a/src/amici.cpp +++ b/src/amici.cpp @@ -237,12 +237,12 @@ std::unique_ptr runAmiciSimulation( gsl_EnsuresDebug(rdata->posteq_cpu_timeB <= rdata->cpu_time_total); if (!posteq) gsl_EnsuresDebug( - std::is_sorted(rdata->numsteps.begin(), rdata->numsteps.end()) + std::ranges::is_sorted(rdata->numsteps) || rdata->status != AMICI_SUCCESS ); if (!preeq) gsl_EnsuresDebug( - std::is_sorted(rdata->numstepsB.begin(), rdata->numstepsB.end()) + std::ranges::is_sorted(rdata->numstepsB) || rdata->status != AMICI_SUCCESS ); rdata->messages = logger.items; diff --git a/src/edata.cpp b/src/edata.cpp index a4c0868ad8..b5c1070784 100644 --- a/src/edata.cpp +++ b/src/edata.cpp @@ -129,7 +129,7 @@ ExpData::ExpData( } void ExpData::setTimepoints(std::vector const& ts) { - if (!std::is_sorted(ts.begin(), ts.end())) + if (!std::ranges::is_sorted(ts)) throw AmiException( "Encountered non-monotonic timepoints, please order timepoints " "such that they are monotonically increasing!" @@ -196,9 +196,7 @@ void ExpData::setObservedDataStdDev( void ExpData::setObservedDataStdDev(realtype const stdDev) { checkSigmaPositivity(stdDev, "stdDev"); - std::fill( - observed_data_std_dev_.begin(), observed_data_std_dev_.end(), stdDev - ); + std::ranges::fill(observed_data_std_dev_, stdDev); } void ExpData::setObservedDataStdDev( @@ -292,9 +290,7 @@ void ExpData::setObservedEventsStdDev( void ExpData::setObservedEventsStdDev(realtype const stdDev) { checkSigmaPositivity(stdDev, "stdDev"); - std::fill( - observed_events_std_dev_.begin(), observed_events_std_dev_.end(), stdDev - ); + std::ranges::fill(observed_events_std_dev_, stdDev); } void ExpData::setObservedEventsStdDev( @@ -339,15 +335,10 @@ realtype const* ExpData::getObservedEventsStdDevPtr(int ie) const { } void ExpData::clear_observations() { - std::fill(observed_data_.begin(), observed_data_.end(), getNaN()); - std::fill( - observed_data_std_dev_.begin(), observed_data_std_dev_.end(), getNaN() - ); - std::fill(observed_events_.begin(), observed_events_.end(), getNaN()); - std::fill( - observed_events_std_dev_.begin(), observed_events_std_dev_.end(), - getNaN() - ); + std::ranges::fill(observed_data_, getNaN()); + std::ranges::fill(observed_data_std_dev_, getNaN()); + std::ranges::fill(observed_events_, getNaN()); + std::ranges::fill(observed_events_std_dev_, getNaN()); } void ExpData::applyDimensions() { diff --git a/src/forwardproblem.cpp b/src/forwardproblem.cpp index d457176acd..f9e83ee00d 100644 --- a/src/forwardproblem.cpp +++ b/src/forwardproblem.cpp @@ -87,9 +87,7 @@ void ForwardProblem::workForwardProblem() { solver->setup(t0, model, x_, dx_, sx_, sdx_); if (model->ne - && std::any_of(roots_found_.begin(), roots_found_.end(), [](int rf) { - return rf == 1; - })) + && std::ranges::any_of(roots_found_, [](int rf) { return rf == 1; })) handleEvent(&t0, false, true); /* perform presimulation if necessary */ @@ -101,10 +99,9 @@ void ForwardProblem::workForwardProblem() { t_ = model->t0(); if (model->ne) { model->initEvents(x_, dx_, roots_found_); - if (std::any_of( - roots_found_.begin(), roots_found_.end(), - [](int rf) { return rf == 1; } - )) + if (std::ranges::any_of(roots_found_, [](int rf) { + return rf == 1; + })) handleEvent(&t0, false, true); } } @@ -136,10 +133,10 @@ void ForwardProblem::workForwardProblem() { // get list of trigger timepoints for fixed-time triggered events auto trigger_timepoints = model->get_trigger_timepoints(); - auto it_trigger_timepoints = std::find_if( - trigger_timepoints.begin(), trigger_timepoints.end(), - [this](auto t) { return t > this->t_; } - ); + auto it_trigger_timepoints + = std::ranges::find_if(trigger_timepoints, [this](auto t) { + return t > this->t_; + }); /* loop over timepoints */ for (it_ = 0; it_ < model->nt(); it_++) { @@ -333,7 +330,7 @@ void ForwardProblem::store_pre_event_state(bool seflag, bool initial_event) { } } if (initial_event) // t0 has no parameter dependency - std::fill(stau_.begin(), stau_.end(), 0.0); + std::ranges::fill(stau_, 0.0); } else if (solver->computingASA()) { /* store x to compute jump in discontinuity */ x_disc_.push_back(x_); diff --git a/src/hdf5.cpp b/src/hdf5.cpp index c8d4ec4b66..e180c789c5 100644 --- a/src/hdf5.cpp +++ b/src/hdf5.cpp @@ -699,8 +699,8 @@ void writeReturnDataDiagnosis( // work-around for macos segfaults, use struct without std::string struct LogItemCStr { int severity; - const char* identifier; - const char* message; + char const* identifier; + char const* message; }; void writeLogItemsToHDF5( @@ -738,8 +738,7 @@ void writeLogItemsToHDF5( // ... therefore, as a workaround, we use a struct without std::string H5::CompType logItemType(sizeof(LogItemCStr)); logItemType.insertMember( - "severity", HOFFSET(LogItemCStr, severity), - H5::PredType::NATIVE_INT + "severity", HOFFSET(LogItemCStr, severity), H5::PredType::NATIVE_INT ); auto vlstr_type = H5::StrType(H5::PredType::C_S1, H5T_VARIABLE); logItemType.insertMember( diff --git a/src/model.cpp b/src/model.cpp index 700d124e55..9edb149483 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -78,7 +78,7 @@ std::map const model_quantity_to_str{ }; static void setNaNtoZero(std::vector& vec) { - std::for_each(vec.begin(), vec.end(), [](double& val) { + std::ranges::for_each(vec, [](double& val) { if (std::isnan(val)) { val = 0.0; } @@ -98,7 +98,7 @@ static realtype getValueById( std::vector const& ids, std::vector const& values, std::string const& id, char const* variable_name, char const* id_name ) { - auto it = std::find(ids.begin(), ids.end(), id); + auto it = std::ranges::find(ids, id); if (it != ids.end()) return values.at(it - ids.begin()); @@ -121,7 +121,7 @@ static void setValueById( realtype value, std::string const& id, char const* variable_name, char const* id_name ) { - auto it = std::find(ids.begin(), ids.end(), id); + auto it = std::ranges::find(ids, id); if (it != ids.end()) values.at(it - ids.begin()) = value; else @@ -338,8 +338,8 @@ void Model::initializeSplineSensitivities() { std::vector tmp_dvalues(allnodes, 0.0); std::vector tmp_dslopes(allnodes, 0.0); for (int ip = 0; ip < nplist(); ip++) { - std::fill(tmp_dvalues.begin(), tmp_dvalues.end(), 0.0); - std::fill(tmp_dslopes.begin(), tmp_dslopes.end(), 0.0); + std::ranges::fill(tmp_dvalues, 0.0); + std::ranges::fill(tmp_dslopes, 0.0); fdspline_valuesdp( tmp_dvalues.data(), state_.unscaledParameters.data(), state_.fixedParameters.data(), plist(ip) @@ -405,7 +405,7 @@ void Model::initEvents( ) { std::vector rootvals(ne, 0.0); froot(simulation_parameters_.tstart_, x, dx, rootvals); - std::fill(roots_found.begin(), roots_found.end(), 0); + std::ranges::fill(roots_found, 0); for (int ie = 0; ie < ne; ie++) { if (rootvals.at(ie) < 0) { state_.h.at(ie) = 0.0; @@ -796,7 +796,7 @@ double Model::getTimepoint(int const it) const { } void Model::setTimepoints(std::vector const& ts) { - if (!std::is_sorted(ts.begin(), ts.end())) + if (!std::ranges::is_sorted(ts)) throw AmiException("Encountered non-monotonic timepoints, please order" " timepoints such that they are monotonically" " increasing!"); @@ -813,9 +813,7 @@ std::vector const& Model::getStateIsNonNegative() const { void Model::setStateIsNonNegative(std::vector const& nonNegative) { auto any_state_non_negative - = std::any_of(nonNegative.begin(), nonNegative.end(), [](bool x) { - return x; - }); + = std::ranges::any_of(nonNegative, [](bool x) { return x; }); if (nx_solver != nx_rdata) { if (any_state_non_negative) throw AmiException("Non-negative states are not supported with" @@ -845,7 +843,7 @@ int Model::plist(int pos) const { return state_.plist.at(pos); } void Model::setParameterList(std::vector const& plist) { int np = this->np(); // cannot capture 'this' in lambda expression - if (std::any_of(plist.begin(), plist.end(), [&np](int idx) { + if (std::ranges::any_of(plist, [&np](int idx) { return idx < 0 || idx >= np; })) { throw AmiException("Indices in plist must be in [0..np]"); @@ -1112,7 +1110,7 @@ void Model::addObservableObjective( std::vector nllh(nJ, 0.0); for (int iyt = 0; iyt < nytrue; iyt++) { if (edata.isSetObservedData(it, iyt)) { - std::fill(nllh.begin(), nllh.end(), 0.0); + std::ranges::fill(nllh, 0.0); fJy(nllh.data(), iyt, state_.unscaledParameters.data(), state_.fixedParameters.data(), derived_state_.y_.data(), derived_state_.sigmay_.data(), edata.getObservedDataPtr(it)); @@ -1303,7 +1301,7 @@ void Model::addEventObjective( std::vector nllh(nJ, 0.0); for (int iztrue = 0; iztrue < nztrue; iztrue++) { if (edata.isSetObservedEvents(nroots, iztrue)) { - std::fill(nllh.begin(), nllh.end(), 0.0); + std::ranges::fill(nllh, 0.0); fJz(nllh.data(), iztrue, state_.unscaledParameters.data(), state_.fixedParameters.data(), derived_state_.z_.data(), derived_state_.sigmaz_.data(), @@ -1323,7 +1321,7 @@ void Model::addEventObjectiveRegularization( std::vector nllh(nJ, 0.0); for (int iztrue = 0; iztrue < nztrue; iztrue++) { if (edata.isSetObservedEvents(nroots, iztrue)) { - std::fill(nllh.begin(), nllh.end(), 0.0); + std::ranges::fill(nllh, 0.0); fJrz( nllh.data(), iztrue, state_.unscaledParameters.data(), state_.fixedParameters.data(), derived_state_.rz_.data(), @@ -1395,7 +1393,7 @@ void Model::getEventTimeSensitivity( AmiVector const& x, AmiVectorArray const& sx ) { - std::fill(stau.begin(), stau.end(), 0.0); + std::ranges::fill(stau, 0.0); for (int ip = 0; ip < nplist(); ip++) { fstau( @@ -1525,7 +1523,7 @@ void Model::updateHeavisideB(int const* rootsfound) { int Model::checkFinite( gsl::span array, ModelQuantity model_quantity, realtype t ) const { - auto it = std::find_if(array.begin(), array.end(), [](realtype x) { + auto it = std::ranges::find_if(array, [](realtype x) { return !std::isfinite(x); }); if (it == array.end()) { @@ -1624,7 +1622,7 @@ int Model::checkFinite( gsl::span array, ModelQuantity model_quantity, size_t num_cols, realtype t ) const { - auto it = std::find_if(array.begin(), array.end(), [](realtype x) { + auto it = std::ranges::find_if(array, [](realtype x) { return !std::isfinite(x); }); if (it == array.end()) { @@ -1739,7 +1737,7 @@ int Model::checkFinite(SUNMatrix m, ModelQuantity model_quantity, realtype t) // check flat array, to see if there are any issues // (faster, in particular for sparse arrays) auto m_flat = gsl::make_span(m); - auto it = std::find_if(m_flat.begin(), m_flat.end(), [](realtype x) { + auto it = std::ranges::find_if(m_flat, [](realtype x) { return !std::isfinite(x); }); if (it == m_flat.end()) { @@ -1831,9 +1829,7 @@ void Model::setAlwaysCheckFinite(bool alwaysCheck) { bool Model::getAlwaysCheckFinite() const { return always_check_finite_; } void Model::fx0(AmiVector& x) { - std::fill( - derived_state_.x_rdata_.begin(), derived_state_.x_rdata_.end(), 0.0 - ); + std::ranges::fill(derived_state_.x_rdata_, 0.0); /* this function also computes initial total abundances */ fx0(derived_state_.x_rdata_.data(), simulation_parameters_.tstart_, state_.unscaledParameters.data(), state_.fixedParameters.data()); @@ -1877,10 +1873,7 @@ void Model::fsx0(AmiVectorArray& sx, AmiVector const& x) { for (int ip = 0; ip < nplist(); ip++) { if (ncl() > 0) stcl = &state_.stotal_cl.at(plist(ip) * ncl()); - std::fill( - derived_state_.sx_rdata_.begin(), derived_state_.sx_rdata_.end(), - 0.0 - ); + std::ranges::fill(derived_state_.sx_rdata_, 0.0); fsx0( derived_state_.sx_rdata_.data(), simulation_parameters_.tstart_, computeX_pos(x), state_.unscaledParameters.data(), @@ -2244,10 +2237,7 @@ void Model::fdJydy(int const it, AmiVector const& x, ExpData const& edata) { } } } else { - std::fill( - derived_state_.dJydy_matlab_.begin(), - derived_state_.dJydy_matlab_.end(), 0.0 - ); + std::ranges::fill(derived_state_.dJydy_matlab_, 0.0); for (int iyt = 0; iyt < nytrue; iyt++) { if (!edata.isSetObservedData(it, iyt)) continue; @@ -2821,7 +2811,7 @@ void Model::fsspl(realtype const t) { void Model::fw(realtype const t, realtype const* x, bool include_static) { if (include_static) { - std::fill(derived_state_.w_.begin(), derived_state_.w_.end(), 0.0); + std::ranges::fill(derived_state_.w_, 0.0); } fspl(t); fw(derived_state_.w_.data(), t, x, state_.unscaledParameters.data(), @@ -3076,7 +3066,7 @@ std::vector Model::get_trigger_timepoints() const { for (auto const& kv : state_independent_events_) { *(it++) = kv.first; } - std::sort(trigger_timepoints.begin(), trigger_timepoints.end()); + std::ranges::sort(trigger_timepoints); return trigger_timepoints; } diff --git a/src/model_dae.cpp b/src/model_dae.cpp index 22025e1181..3bdd277559 100644 --- a/src/model_dae.cpp +++ b/src/model_dae.cpp @@ -103,7 +103,7 @@ void Model_DAE::froot( void Model_DAE::froot( realtype t, const_N_Vector x, const_N_Vector dx, gsl::span root ) { - std::fill(root.begin(), root.end(), 0.0); + std::ranges::fill(root, 0.0); auto x_pos = computeX_pos(x); froot( root.data(), t, N_VGetArrayPointerConst(x_pos), diff --git a/src/model_ode.cpp b/src/model_ode.cpp index 787df210ef..d1fcfe4b99 100644 --- a/src/model_ode.cpp +++ b/src/model_ode.cpp @@ -91,7 +91,7 @@ void Model_ODE::froot( void Model_ODE::froot(realtype t, const_N_Vector x, gsl::span root) { auto x_pos = computeX_pos(x); - std::fill(root.begin(), root.end(), 0.0); + std::ranges::fill(root, 0.0); froot( root.data(), t, N_VGetArrayPointerConst(x_pos), state_.unscaledParameters.data(), state_.fixedParameters.data(), diff --git a/src/rdata.cpp b/src/rdata.cpp index 460e9bd674..108e06fb6e 100644 --- a/src/rdata.cpp +++ b/src/rdata.cpp @@ -70,7 +70,8 @@ ReturnData::ReturnData( void ReturnData::initializeLikelihoodReporting(bool enable_fim) { llh = getNaN(); chi2 = getNaN(); - if (sensi >= SensitivityOrder::first && sensi_meth != SensitivityMethod::none) { + if (sensi >= SensitivityOrder::first + && sensi_meth != SensitivityMethod::none) { sllh.resize(nplist, getNaN()); if (sensi >= SensitivityOrder::second) s2llh.resize(nplist * (nJ - 1), getNaN()); @@ -636,8 +637,8 @@ void ReturnData::invalidateLLH() { void ReturnData::invalidateSLLH() { if (!sllh.empty()) { - std::fill(sllh.begin(), sllh.end(), getNaN()); - std::fill(s2llh.begin(), s2llh.end(), getNaN()); + std::ranges::fill(sllh, getNaN()); + std::ranges::fill(s2llh, getNaN()); } } @@ -814,8 +815,8 @@ void ReturnData::initializeObjectiveFunction(bool enable_chi2) { || rdata_reporting == RDataReporting::observables_likelihood || rdata_reporting == RDataReporting::full) { llh = 0.0; - std::fill(sllh.begin(), sllh.end(), 0.0); - std::fill(s2llh.begin(), s2llh.end(), 0.0); + std::ranges::fill(sllh, 0.0); + std::ranges::fill(s2llh, 0.0); } if ((rdata_reporting == RDataReporting::residuals || rdata_reporting == RDataReporting::full) diff --git a/src/solver.cpp b/src/solver.cpp index 298caaf774..19776342b0 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -763,9 +763,7 @@ int Solver::getMaxConvFails() const { return max_conv_fails_; } void Solver::setConstraints(std::vector const& constraints) { auto any_constraint - = std::any_of(constraints.begin(), constraints.end(), [](bool x) { - return x != 0.0; - }); + = std::ranges::any_of(constraints, [](bool x) { return x != 0.0; }); if (!any_constraint) { // all-0 must be converted to empty, otherwise sundials will fail diff --git a/src/splinefunctions.cpp b/src/splinefunctions.cpp index 0b07a75aa9..c65d48c3eb 100644 --- a/src/splinefunctions.cpp +++ b/src/splinefunctions.cpp @@ -811,12 +811,12 @@ void HermiteSpline::compute_final_sensitivity( */ int last = n_nodes() - 1; if (get_node_derivative_scaled(last) == 0) - std::fill(finalSensitivity.begin(), finalSensitivity.end(), NAN); + std::ranges::fill(finalSensitivity, NAN); } else if (last_node_ep_ == SplineExtrapolation::polynomial) { /* Yes, that's not correct. But I don't see any good reason for * implementing a case, which anybody with more than a dead fish * between the ears will never use. */ - std::fill(finalSensitivity.begin(), finalSensitivity.end(), NAN); + std::ranges::fill(finalSensitivity, NAN); } else { /* Periodic: will not yield a steady state * (unless the spline is the constant funtion, @@ -824,7 +824,7 @@ void HermiteSpline::compute_final_sensitivity( * whether the steady state continues to exist in a neighbourhood of the * current parameters */ - std::fill(finalSensitivity.begin(), finalSensitivity.end(), NAN); + std::ranges::fill(finalSensitivity, NAN); } set_final_sensitivity_scaled(finalSensitivity); } diff --git a/src/steadystateproblem.cpp b/src/steadystateproblem.cpp index 7c3ac9fab3..c78a80be32 100644 --- a/src/steadystateproblem.cpp +++ b/src/steadystateproblem.cpp @@ -609,11 +609,9 @@ realtype SteadystateProblem::getWrmsFSA(Model& model) { bool SteadystateProblem::checkSteadyStateSuccess() const { /* Did one of the attempts yield s steady state? */ - return std::any_of( - steady_state_status_.begin(), steady_state_status_.end(), - [](SteadyStateStatus status) { - return status == SteadyStateStatus::success; - } + return std::ranges::any_of( + steady_state_status_, [](SteadyStateStatus status + ) { return status == SteadyStateStatus::success; } ); } diff --git a/src/sundials_matrix_wrapper.cpp b/src/sundials_matrix_wrapper.cpp index a5847d982f..89601e882e 100644 --- a/src/sundials_matrix_wrapper.cpp +++ b/src/sundials_matrix_wrapper.cpp @@ -467,10 +467,9 @@ void SUNMatrixWrapper::sparse_add( void SUNMatrixWrapper::sparse_sum(std::vector const& mats) { // matrix_ == nullptr is allowed on the first call - auto all_empty - = std::all_of(mats.begin(), mats.end(), [](SUNMatrixWrapper const& m) { - return !m.matrix_; - }); + auto all_empty = std::ranges::all_of(mats, [](SUNMatrixWrapper const& m) { + return !m.matrix_; + }); if (all_empty) return; diff --git a/src/vector.cpp b/src/vector.cpp index 78b3fe5521..df304d2caf 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -26,12 +26,10 @@ int AmiVector::getLength() const { return gsl::narrow(vec_.size()); } void AmiVector::zero() { set(0.0); } void AmiVector::minus() { - std::transform( - vec_.begin(), vec_.end(), vec_.begin(), std::negate() - ); + std::ranges::transform(vec_, vec_.begin(), std::negate()); } -void AmiVector::set(realtype val) { std::fill(vec_.begin(), vec_.end(), val); } +void AmiVector::set(realtype val) { std::ranges::fill(vec_, val); } realtype& AmiVector::operator[](int pos) { return vec_.at(gsl::narrow(pos)); @@ -52,7 +50,7 @@ void AmiVector::copy(AmiVector const& other) { "match input dimension (%i)", getLength(), other.getLength() ); - std::copy(other.vec_.begin(), other.vec_.end(), vec_.begin()); + std::ranges::copy(other.vec_, vec_.begin()); } void AmiVector::synchroniseNVector(SUNContext sunctx) { From ebcf485b4ef05628fa98119393b2e024232df4a9 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Wed, 23 Apr 2025 11:12:29 +0200 Subject: [PATCH 2/2] gcc10.1 --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f673c7686..c2a713d3b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MINGW") - # require at least gcc 9.1 for proper C+17 support, e.g. std::reduce - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) - message(FATAL_ERROR "GCC version must be at least 9.1!") + # require at least gcc 10.1 for std::ranges (C++20) support + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.1) + message(FATAL_ERROR "GCC version must be at least 10.1!") endif() endif()