diff --git a/src/cosim/slave_simulator.cpp b/src/cosim/slave_simulator.cpp index c16f2d17..2c9492f4 100644 --- a/src/cosim/slave_simulator.cpp +++ b/src/cosim/slave_simulator.cpp @@ -549,25 +549,19 @@ class slave_simulator::impl void initialize_start_values() { auto deltaT = duration::zero(); - auto filter = [this](const value_reference& vr, const std::variant& vt) { - variable_type type; - std::visit( - visitor( - [&](double) { type = variable_type::real; }, - [&](int) { type = variable_type::integer; }, - [&](bool) { type = variable_type::boolean; }, - [&](const std::string&) { type = variable_type::string; }), - vt); - const auto& vd = this->find_variable_description(vr, type); - /// FMI Specification 2.0.4 - Section 4.2.4 - return vd.variability != variable_variability::constant && - vd.causality != variable_causality::input; + auto filter = [this](const variable_type& vt) { + return [this, &vt](const value_reference& vr, const std::variant&) { + const auto& vd = this->find_variable_description(vr, vt); + /// FMI Specification 2.0.4 - Section 4.2.4 + return vd.variability != variable_variability::constant && + vd.causality != variable_causality::input; + }; }; - - const auto [realRefs, realValues] = realSetCache_.modify_and_get(deltaT, filter); - const auto [integerRefs, integerValues] = integerSetCache_.modify_and_get(deltaT, filter); - const auto [booleanRefs, booleanValues] = booleanSetCache_.modify_and_get(deltaT, filter); - const auto [stringRefs, stringValues] = stringSetCache_.modify_and_get(deltaT, filter); + + const auto [realRefs, realValues] = realSetCache_.modify_and_get(deltaT, filter(variable_type::real)); + const auto [integerRefs, integerValues] = integerSetCache_.modify_and_get(deltaT, filter(variable_type::integer)); + const auto [booleanRefs, booleanValues] = booleanSetCache_.modify_and_get(deltaT, filter(variable_type::boolean)); + const auto [stringRefs, stringValues] = stringSetCache_.modify_and_get(deltaT, filter(variable_type::string)); slave_->set_variables( gsl::make_span(realRefs),