Skip to content

Commit

Permalink
Fix constructor in CommonOption
Browse files Browse the repository at this point in the history
  • Loading branch information
aartdem committed Dec 7, 2023
1 parent f221ea1 commit c43eb56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions src/core/config/common_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,24 @@ class CommonOption {
typename Option<T>::DefaultFunc const default_func_;

public:
CommonOption(std::string_view name, std::string_view description,
std::optional<T> default_value,
typename Option<T>::NormalizeFunc normalize_func = nullptr,
typename Option<T>::ValueCheckFunc value_check_func = nullptr)
: name_(name),
description_(description),
default_value_(default_value),
normalize_func_(normalize_func),
value_check_func_(value_check_func),
default_func_(nullptr) {}
using DefaultFuncType = typename Option<T>::DefaultFunc;

CommonOption(std::string_view name, std::string_view description,
std::variant<std::optional<T>, DefaultFuncType> default_init_v = std::nullopt,
typename Option<T>::NormalizeFunc normalize_func = nullptr,
typename Option<T>::ValueCheckFunc value_check_func = nullptr,
typename Option<T>::DefaultFunc default_func = nullptr)
typename Option<T>::ValueCheckFunc value_check_func = nullptr)
: name_(name),
description_(description),
default_value_(std::nullopt),
normalize_func_(normalize_func),
value_check_func_(value_check_func),
default_func_(default_func) {}
value_check_func_(value_check_func) {
if (std::holds_alternative<DefaultFuncType>(default_init_v)) {
default_func_ = std::get<DefaultFuncType>(default_init_v);
default_value_ = std::nullopt;
} else {
default_func_ = nullptr;
default_value_ = std::get<std::optional<T>>(default_init_v);
}
}

[[nodiscard]] Option<T> operator()(T *value_ptr) const {
auto option = default_value_.has_value()
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/thread_number/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace config {
using names::kThreads, descriptions::kDThreads;
extern const CommonOption<ThreadNumType> ThreadNumberOpt{
kThreads, kDThreads, static_cast<int>(0), [](auto &value) {
kThreads, kDThreads, 0, [](auto &value) {
if (value == 0) {
value = std::thread::hardware_concurrency();
if (value == 0) {
Expand Down

0 comments on commit c43eb56

Please sign in to comment.