0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::json: Add get<string_view>() to doc.

This commit is contained in:
Jason Volk 2017-04-02 20:53:56 -07:00
parent 49da778def
commit ff84531ea3

View file

@ -52,6 +52,7 @@ struct doc
template<class T> T at(const string_view &name) const;
string_view operator[](const string_view &name) const;
template<class T = string_view> T get(const string_view &name, const T &def = T()) const;
string_view get(const string_view &name, const string_view &def = {}) const;
explicit operator std::string() const;
@ -116,6 +117,15 @@ struct doc::const_iterator
} // namespace json
} // namespace ircd
inline ircd::string_view
ircd::json::doc::get(const string_view &name,
const string_view &def)
const
{
const string_view sv(operator[](name));
return !sv.empty()? sv : def;
}
template<class T>
T
ircd::json::doc::get(const string_view &name,