From 723cd3440bacc0f080f33f0b51fb8116eec347a7 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 11 Oct 2017 18:07:47 -0700 Subject: [PATCH] ircd::json: Towards uniform defined(). --- include/ircd/json/member.h | 7 +++++++ include/ircd/json/value.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/include/ircd/json/member.h b/include/ircd/json/member.h index 4cbdff14c..91e4b790e 100644 --- a/include/ircd/json/member.h +++ b/include/ircd/json/member.h @@ -58,6 +58,7 @@ struct ircd::json::member friend bool operator!=(const member &a, const string_view &b); friend bool operator<(const member &a, const string_view &b); + friend bool defined(const member &); friend size_t serialized(const member &); friend string_view stringify(mutable_buffer &, const member &); friend std::ostream &operator<<(std::ostream &, const member &); @@ -132,3 +133,9 @@ ircd::json::operator==(const member &a, const string_view &b) { return string_view{a.first.string, a.first.len} == b; } + +inline bool +ircd::json::defined(const member &a) +{ + return defined(a.second); +} diff --git a/include/ircd/json/value.h b/include/ircd/json/value.h index e47b5860a..b2fdfce0a 100644 --- a/include/ircd/json/value.h +++ b/include/ircd/json/value.h @@ -129,6 +129,7 @@ struct ircd::json::value friend bool operator>(const value &a, const value &b); friend enum type type(const value &a); + friend bool defined(const value &); friend size_t serialized(const value &); friend string_view stringify(mutable_buffer &, const value &); friend std::ostream &operator<<(std::ostream &, const value &); @@ -332,6 +333,12 @@ noexcept return *this; } +inline bool +ircd::json::defined(const value &a) +{ + return !a.undefined(); +} + inline enum ircd::json::type ircd::json::type(const value &a) {