mirror of
https://github.com/modelec/cpp-lib.git
synced 2026-01-18 16:17:22 +01:00
template get option
This commit is contained in:
@@ -19,7 +19,24 @@ public:
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<T>(std::stod(_options.at(option)));
|
try {
|
||||||
|
return static_cast<T>(std::stod(_options.at(option)));
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] std::optional<T> getOption(const std::string& option) const {
|
||||||
|
if (!hasOption(option)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return static_cast<T>(std::stod(_options.at(option)));
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::optional<std::string> getOption(const std::string& option) const;
|
[[nodiscard]] std::optional<std::string> getOption(const std::string& option) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user