From c6be9681110455eb2e70cf06c5c4127eb57d4437 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 17 Jan 2019 13:15:02 -0800 Subject: [PATCH] ircd::json::tuple: Various keys suite cleanup / simplify. --- include/ircd/json/tuple/keys.h | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/include/ircd/json/tuple/keys.h b/include/ircd/json/tuple/keys.h index 428433039..38e22b70d 100644 --- a/include/ircd/json/tuple/keys.h +++ b/include/ircd/json/tuple/keys.h @@ -34,7 +34,7 @@ struct ircd::json::keys operator vector_view() const; - constexpr keys(const selection & = {}); + keys(const selection & = {}); }; /// Selection of keys in a tuple represented by a bitset. Users generally @@ -45,15 +45,15 @@ struct ircd::json::keys::selection :std::bitset { template - constexpr bool until(closure &&function) const; + constexpr bool until(closure&& function) const; template - constexpr void for_each(closure &&function) const; + constexpr void for_each(closure&& function) const; - template - constexpr it_a transform(it_a it, const it_b end) const; + template + constexpr it transform(it, const it end) const; + // Note the default all-bits set. constexpr selection(const uint64_t &val = -1) :std::bitset{val} {} @@ -106,30 +106,29 @@ struct ircd::json::keys::exclude // template -template -constexpr it_a -ircd::json::keys::selection::transform(it_a it, - const it_b end) +template +constexpr it +ircd::json::keys::selection::transform(it i, + const it end) const { - this->until([&it, &end](auto&& key) + this->until([&i, &end](auto&& key) { - if(it == end) + if(i == end) return false; - *it = key; - ++it; + *i = key; + ++i; return true; }); - return it; + return i; } template template constexpr void -ircd::json::keys::selection::for_each(closure &&function) +ircd::json::keys::selection::for_each(closure&& function) const { this->until([&function](auto&& key) @@ -142,7 +141,7 @@ const template template constexpr bool -ircd::json::keys::selection::until(closure &&function) +ircd::json::keys::selection::until(closure&& function) const { for(size_t i(0); i < tuple::size(); ++i) @@ -158,7 +157,6 @@ const // template -constexpr ircd::json::keys::keys(const selection &selection) { selection.transform(this->begin(), this->end()); @@ -179,7 +177,7 @@ const { const auto &start { - begin(*this) + this->begin() }; const auto &stop @@ -187,7 +185,8 @@ const start + this->count() }; - return std::find(start, stop, key) != stop; + assert(!empty(key)); + return stop != std::find(start, stop, key); } template