Skip to content

Commit 03d9070

Browse files
committed
Update to visitor
1 parent 299fc3d commit 03d9070

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/run.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include <chrono>
2323
#include <memory>
24+
#include <variant>
25+
#include <type_traits>
2426

2527

2628
void run_subcommand::setup_options(
@@ -72,6 +74,12 @@ void run_subcommand::setup_options(
7274
namespace
7375
{
7476

77+
template<class... Ts>
78+
struct overloaded : Ts... { using Ts::operator()...; };
79+
80+
template<class... Ts>
81+
overloaded(Ts...) -> overloaded<Ts...>;
82+
7583
cosim::execution load_system_structure(
7684
const cosim::filesystem::path& path,
7785
cosim::model_uri_resolver& uriResolver,
@@ -84,14 +92,15 @@ cosim::execution load_system_structure(
8492
const auto config = cosim::load_osp_config(path, uriResolver);
8593
std::shared_ptr<cosim::algorithm> algorithm;
8694

87-
std::visit([&algorithm, &config, &workerThreadCount](auto&& value) {
88-
using T = std::decay_t<decltype(value)>;
89-
if constexpr (std::is_same_v<T, cosim::fixed_step_algorithm_params>) {
90-
algorithm = std::make_shared<cosim::fixed_step_algorithm>(std::get<cosim::fixed_step_algorithm_params>(config.algorithm_configuration), workerThreadCount);
91-
} else if constexpr (std::is_same_v<T, cosim::ecco_algorithm_params>) {
92-
algorithm = std::make_shared<cosim::ecco_algorithm>(std::get<cosim::ecco_algorithm_params>(config.algorithm_configuration), workerThreadCount);
93-
}
94-
}, config.algorithm_configuration);
95+
std::visit(
96+
overloaded{
97+
[&algorithm, &workerThreadCount](const cosim::fixed_step_algorithm_params& params) {
98+
algorithm = std::make_shared<cosim::fixed_step_algorithm>(params, workerThreadCount);
99+
},
100+
[&algorithm, &workerThreadCount](const cosim::ecco_algorithm_params& params) {
101+
algorithm = std::make_shared<cosim::ecco_algorithm>(params, workerThreadCount);
102+
}},
103+
config.algorithm_configuration);
95104

96105
auto execution = cosim::execution(startTime, algorithm);
97106
cosim::inject_system_structure(

0 commit comments

Comments
 (0)