瀏覽代碼

read_opt can deal with non-optional values

default_compile_flags
vector-of-bool 5 年之前
父節點
當前提交
8d1e707e83
共有 1 個檔案被更改,包括 6 行新增5 行删除
  1. +6
    -5
      src/libman/parse.hpp

+ 6
- 5
src/libman/parse.hpp 查看文件

@@ -157,11 +157,12 @@ public:

template <typename T>
class read_opt {
std::string_view _key;
std::optional<T>& _ref;
std::string_view _key;
T& _ref;
bool _did_read = false;

public:
read_opt(std::string_view key, std::optional<T>& ref)
read_opt(std::string_view key, T& ref)
: _key(key)
, _ref(ref) {}

@@ -169,11 +170,11 @@ public:
if (key != _key) {
return 0;
}
if (_ref.has_value()) {
if (_did_read) {
throw std::runtime_error(std::string(context) + ": Duplicated key '" + std::string(key)
+ "' is not allowed.");
}
_ref.emplace(value);
_ref = T(value);
return 1;
}


Loading…
取消
儲存