Browse Source

reject_unknown() will throw on invalid keys

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

+ 12
- 3
src/libman/parse.hpp View File

@@ -226,12 +226,21 @@ public:
void validate(std::string_view) {}
};

class reject_unknown {
public:
int read_one(std::string_view context, std::string_view key, std::string_view) const {
throw std::runtime_error(std::string(context) + ": Unknown key '" + std::string(key) + "'");
}

void validate(std::string_view) {}
};

template <typename... Items>
auto read(std::string_view context [[maybe_unused]], const pair_list& pairs, Items... is) {
auto read(std::string_view context[[maybe_unused]], const pair_list& pairs, Items... is) {
std::vector<pair> bad_pairs;
for (auto [key, value] : pairs.items()) {
auto nread = (is.read_one(context, key, value) + ... + 0);
if (nread == 0) {
auto did_read = (is.read_one(context, key, value) || ...);
if (did_read) {
bad_pairs.emplace_back(key, value);
}
}

Loading…
Cancel
Save