Browse Source

read_opt can deal with non-optional values

default_compile_flags
vector-of-bool 5 years ago
parent
commit
8d1e707e83
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      src/libman/parse.hpp

+ 6
- 5
src/libman/parse.hpp View File

@@ -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…
Cancel
Save