0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 18:38:52 +02:00

ircd::json: Add non-const iov::at(); minor cleanup.

This commit is contained in:
Jason Volk 2018-05-25 17:45:49 -07:00
parent d4c2ec6b22
commit b69848b620
2 changed files with 29 additions and 7 deletions

View file

@ -55,6 +55,7 @@ struct ircd::json::iov
public:
bool has(const string_view &key) const;
const value &at(const string_view &key) const;
value &at(const string_view &key);
iov() = default;

View file

@ -987,15 +987,25 @@ ircd::json::serialized(const iov &iov)
});
}
bool
ircd::json::iov::has(const string_view &key)
const
ircd::json::value &
ircd::json::iov::at(const string_view &key)
{
return std::any_of(std::begin(*this), std::end(*this), [&key]
(const auto &member)
const auto it
{
return string_view{member.first} == key;
});
std::find_if(std::begin(*this), std::end(*this), [&key]
(const auto &member)
{
return string_view{member.first} == key;
})
};
if(it == std::end(*this))
throw not_found
{
"key '%s' not found", key
};
return it->second;
}
const ircd::json::value &
@ -1020,6 +1030,17 @@ const
return it->second;
}
bool
ircd::json::iov::has(const string_view &key)
const
{
return std::any_of(std::begin(*this), std::end(*this), [&key]
(const auto &member)
{
return string_view{member.first} == key;
});
}
ircd::json::iov::add::add(iov &iov,
member member)
:node