// Matrix Construct // // Copyright (C) Matrix Construct Developers, Authors & Contributors // Copyright (C) 2016-2018 Jason Volk // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. #pragma once #define HAVE_IRCD_JSON_TUPLE_KEYS_H namespace ircd { namespace json { template struct tuple::keys :std::array::size()> { struct selection; struct include; struct exclude; constexpr keys() { _key_transform>(this->begin(), this->end()); } }; template struct tuple::keys::selection :std::bitset::size()> { template constexpr bool until(closure &&function) const { for(size_t i(0); i < this->size(); ++i) if(this->test(i)) if(!function(key, i>())) return false; return true; } template constexpr void for_each(closure &&function) const { this->until([&function](auto&& key) { function(key); return true; }); } template constexpr auto transform(it_a it, const it_b end) const { this->until([&it, &end](auto&& key) { if(it == end) return false; *it = key; ++it; return true; }); } }; template struct tuple::keys::include :selection { constexpr include(const std::initializer_list &list) { for(const auto &key : list) this->set(indexof>(key), true); } }; template struct tuple::keys::exclude :selection { constexpr exclude(const std::initializer_list &list) { this->set(); for(const auto &key : list) this->set(indexof>(key), false); } }; } // namespace json } // namespace ircd