Skip to content

Commit

Permalink
style.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 8, 2024
1 parent d90e3d8 commit 3244f79
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/search/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ void add_evaluator_options_to_feature(plugins::Feature &feature) {
tuple<string, utils::Verbosity> get_evaluator_arguments_from_options(
const plugins::Options &opts) {
return tuple_cat(
make_tuple(opts.get<string>("description")),
utils::get_log_arguments_from_options(opts)
);
make_tuple(opts.get<string>("description")),
utils::get_log_arguments_from_options(opts)
);
}

static class EvaluatorCategoryPlugin : public plugins::TypedCategoryPlugin<Evaluator> {
Expand Down
1 change: 0 additions & 1 deletion src/search/lp/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void add_lp_solver_option_to_feature(plugins::Feature &feature) {
tuple<LPSolverType> get_lp_solver_arguments_from_options(
const plugins::Options &opts) {
return make_tuple(opts.get<LPSolverType>("lpsolver"));

}

LPConstraint::LPConstraint(double lower_bound, double upper_bound)
Expand Down
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/merge_tree_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void MergeTreeFactory::add_options_to_feature(plugins::Feature &feature) {

tuple<int, UpdateOption> get_merge_tree_arguments_from_options(const plugins::Options &opts) {
return make_tuple(
opts.get<int>("random_seed"),
opts.get<UpdateOption>("update_option")
);
opts.get<int>("random_seed"),
opts.get<UpdateOption>("update_option")
);
}

static class MergeTreeFactoryCategoryPlugin : public plugins::TypedCategoryPlugin<MergeTreeFactory> {
Expand Down
16 changes: 8 additions & 8 deletions src/search/operator_counting/operator_counting_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ using namespace std;

namespace operator_counting {
OperatorCountingHeuristic::OperatorCountingHeuristic(
const vector<shared_ptr<ConstraintGenerator>> &constraint_generators,
bool use_integer_operator_counts,
lp::LPSolverType lp_solver_type,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity)
const vector<shared_ptr<ConstraintGenerator>> &constraint_generators,
bool use_integer_operator_counts,
lp::LPSolverType lp_solver_type,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity)
: Heuristic(transform, cache_estimates, description, verbosity),
constraint_generators(constraint_generators),
use_integer_operator_counts(use_integer_operator_counts),
Expand Down Expand Up @@ -123,7 +123,7 @@ class OperatorCountingHeuristicFeature : public plugins::TypedFeature<Evaluator,
options.get<bool>("use_integer_operator_counts"),
lp::get_lp_solver_arguments_from_options(options),
Heuristic::get_heuristic_arguments_from_options(options)
);
);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_multiple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void add_multiple_options_to_feature(plugins::Feature &feature) {
}

tuple<int, int, double, double, double, double, bool, int, utils::Verbosity>
get_multiple_arguments_from_options(const plugins::Options &opts) {
get_multiple_arguments_from_options(const plugins::Options &opts) {
auto generator_args = get_generator_arguments_from_options(opts);
tuple multiple_args = make_tuple(
opts.get<int>("max_pdb_size"),
Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_multiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern void add_multiple_options_to_feature(
plugins::Feature &feature);

extern std::tuple<int, int, double, double, double, double, bool, int, utils::Verbosity>
get_multiple_arguments_from_options(const plugins::Options &opts);
get_multiple_arguments_from_options(const plugins::Options &opts);
}

#endif
10 changes: 5 additions & 5 deletions src/search/plugins/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ class TypedFeature : public FeatureAuto<Constructed> {
constructor. The resulting arguments will be used as arguments to make_shared.
*/
// TODO issue1082 where should this live? optimize with std::forward?
template<typename T, typename ...Arguments>
std::shared_ptr<T> make_shared_from_arg_tuples(Arguments...arguments) {
template<typename T, typename ... Arguments>
std::shared_ptr<T> make_shared_from_arg_tuples(Arguments... arguments) {
return std::apply(
[](auto...flattened_args) {
return std::make_shared<T>(flattened_args...);
[](auto... flattened_args) {
return std::make_shared<T>(flattened_args ...);
},
utils::flatten_tuple(std::tuple<Arguments...>(arguments...)));
utils::flatten_tuple(std::tuple<Arguments...>(arguments ...)));
}

class Plugin {
Expand Down
54 changes: 30 additions & 24 deletions src/search/utils/tuples.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,69 @@
namespace utils {
template<class U, class T, bool can_move>
struct wrapper {
T* ptr;
wrapper(T& t) : ptr(std::addressof(t)) {}
T *ptr;
wrapper(T &t) : ptr(std::addressof(t)) {}

using unwrapped_type =
std::conditional_t<can_move,
std::conditional_t<std::is_lvalue_reference<U>{}, T&, T&&>,
std::conditional_t<std::is_rvalue_reference<U>{}, T&&, T&>>;
std::conditional_t < can_move,
std::conditional_t < std::is_lvalue_reference<U> {}, T &, T && >,
std::conditional_t < std::is_rvalue_reference<U> {}, T &&, T & >>;
using tuple_element_type = U;

unwrapped_type unwrap() const{
unwrapped_type unwrap() const {
return std::forward<unwrapped_type>(*ptr);
}
};

template<class... Wrappers, std::size_t... Is>
auto unwrap_tuple(const std::tuple<Wrappers...>& t, std::index_sequence<Is...>) {
template<class ... Wrappers, std::size_t... Is>
auto unwrap_tuple(const std::tuple<Wrappers...> &t, std::index_sequence<Is...>) {
return std::tuple<typename Wrappers::tuple_element_type...>(std::get<Is>(t).unwrap()...);
}

template<class... Wrappers>
auto unwrap_tuple(const std::tuple<Wrappers...>& t) {
template<class ... Wrappers>
auto unwrap_tuple(const std::tuple<Wrappers...> &t) {
return unwrap_tuple(t, std::index_sequence_for<Wrappers...>());
}

template<bool can_move, class V, class T>
auto wrap_and_flatten(T& t, char){
auto wrap_and_flatten(T &t, char) {
return std::make_tuple(wrapper<V, T, can_move>(t));
}
template<class T> struct is_tuple : std::false_type {};
template<class... Ts> struct is_tuple<std::tuple<Ts...>> : std::true_type {};
template<class T> struct is_tuple<const T> : is_tuple<T> {};
template<class T> struct is_tuple<volatile T> : is_tuple<T> {};
template<class T>
struct is_tuple : std::false_type {};
template<class ... Ts>
struct is_tuple<std::tuple<Ts...>> : std::true_type {};
template<class T>
struct is_tuple<const T> : is_tuple<T> {};
template<class T>
struct is_tuple<volatile T> : is_tuple<T> {};

template<bool can_move, class, class Tuple,
class = std::enable_if_t<is_tuple<std::decay_t<Tuple>>{}>>
auto wrap_and_flatten(Tuple& t, int);
class = std::enable_if_t < is_tuple<std::decay_t<Tuple>>{} > >
auto wrap_and_flatten(Tuple &t, int);

template<bool can_move, class Tuple, std::size_t... Is>
auto wrap_and_flatten(Tuple& t, std::index_sequence<Is...>) {
auto wrap_and_flatten(Tuple &t, std::index_sequence<Is...>) {
return std::tuple_cat(wrap_and_flatten<can_move, std::tuple_element_t<Is, std::remove_cv_t<Tuple>>>(std::get<Is>(t), 0)...);
}

template<bool can_move, class V, class Tuple, class>
auto wrap_and_flatten(Tuple& t, int) {
using seq_type = std::make_index_sequence<std::tuple_size<Tuple>{}>;
auto wrap_and_flatten(Tuple &t, int) {
using seq_type = std::make_index_sequence < std::tuple_size<Tuple> {}
>;
return wrap_and_flatten<can_move>(t, seq_type());
}

template<class Tuple>
auto wrap_and_flatten_tuple(Tuple&& t){
auto wrap_and_flatten_tuple(Tuple &&t) {
constexpr bool can_move = !std::is_lvalue_reference<Tuple>{};
using seq_type = std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>{}>;
using seq_type = std::make_index_sequence < std::tuple_size<std::decay_t<Tuple>> {}
>;
return wrap_and_flatten<can_move>(t, seq_type());
}

template <typename T>
auto flatten_tuple(T&& t) {
template<typename T>
auto flatten_tuple(T &&t) {
return unwrap_tuple(wrap_and_flatten_tuple(std::forward<T>(t)));
}
}
Expand Down

0 comments on commit 3244f79

Please sign in to comment.