Skip to content

Commit

Permalink
[issue1082] reduce boiler plate.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 6, 2024
1 parent 9887d7c commit 4b865dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/search/heuristics/hm_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ class HMHeuristicFeature : public plugins::TypedFeature<Evaluator, HMHeuristic>
}

virtual shared_ptr<HMHeuristic> create_component(const plugins::Options &options, const utils::Context &) const override {
auto parameter_tuple = make_shared<tuple<int, shared_ptr<AbstractTask>, bool, string, utils::Verbosity>>(tuple_cat(make_tuple(options.get<int>("m")),
*Heuristic::get_heuristic_parameters_from_options(options)));
return plugins::make_shared_from_tuple<HMHeuristic>(parameter_tuple);
return plugins::make_shared_from_args_tuple_and_args<HMHeuristic>(
Heuristic::get_heuristic_parameters_from_options(options),
options.get<int>("m")
);
}
};

Expand Down
14 changes: 10 additions & 4 deletions src/search/plugins/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ class TypedFeature : public FeatureAuto<Constructed> {
}
};

// TODO issue1082 where should this live?
// Treats first parameter as pointer to a tuple of arguments for the base class,
// the rest as singleton arguments for the class T.
// TODO issue1082 where should this live? optimize with std::forward?
// Apply the arguments extracted from *parameter_tuple* to make_shared<T>
template<typename T, typename ... Args>
std::shared_ptr<T> make_shared_from_tuple(std::shared_ptr<std::tuple<Args...>> parameter_tuple) {
return apply([](auto... args) {return make_shared<T>(args ...);}, *parameter_tuple);
template<typename T, typename ParentTuple, typename ... ChildSingletons>
std::shared_ptr<T> make_shared_from_args_tuple_and_args(ParentTuple parent_tuple, ChildSingletons ... child_singletons) {
return std::apply([](auto ... args) {
return make_shared<T>(args ...);
},
std::tuple_cat(std::make_tuple(child_singletons ...), *parent_tuple)
);
}

class Plugin {
Expand Down

0 comments on commit 4b865dd

Please sign in to comment.