@@ -31,27 +31,35 @@ namespace facebook::velox::config {
3131// / externally managed system configuration.
3232class IConfig {
3333 public:
34+ template <typename T>
35+ std::optional<T> get (const std::string& key) const {
36+ return get<T>(
37+ key, std::function<T (std::string, std::string)>(defaultConverter<T>));
38+ }
39+
3440 template <typename T>
3541 std::optional<T> get (
3642 const std::string& key,
37- const std::function<T(std::string, std::string)>& toT =
38- [](auto /* unused */ , auto value) {
39- return folly::to<T>(value);
40- }) const {
43+ const std::function<T(std::string, std::string)>& toT) const {
4144 if (auto val = access (key)) {
4245 return toT (key, *val);
4346 }
4447 return std::nullopt ;
4548 }
4649
50+ template <typename T>
51+ T get (const std::string& key, const T& defaultValue) const {
52+ return get<T>(
53+ key,
54+ defaultValue,
55+ std::function<T (std::string, std::string)>(defaultConverter<T>));
56+ }
57+
4758 template <typename T>
4859 T get (
4960 const std::string& key,
5061 const T& defaultValue,
51- const std::function<T(std::string, std::string)>& toT =
52- [](auto /* unused */ , auto value) {
53- return folly::to<T>(value);
54- }) const {
62+ const std::function<T(std::string, std::string)>& toT) const {
5563 if (auto val = access (key)) {
5664 return toT (key, *val);
5765 }
@@ -64,6 +72,13 @@ class IConfig {
6472 virtual ~IConfig () = default ;
6573
6674 private:
75+ template <typename T>
76+ static T defaultConverter (
77+ std::string /* unused */ ,
78+ const std::string& value) {
79+ return folly::to<T>(value);
80+ }
81+
6782 virtual std::optional<std::string> access (const std::string& key) const = 0;
6883};
6984
0 commit comments