// 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_GET_H namespace ircd { namespace json { template inline enable_if_tuple()> &> get(const tuple &t) noexcept { constexpr size_t idx { indexof() }; const auto &ret { val(t) }; return ret; } template inline enable_if_tuple()>> get(const tuple &t, const tuple_value_type()> &def) noexcept { constexpr size_t idx { indexof() }; const auto &ret { val(t) }; return defined(json::value(ret))? ret : def; } template inline enable_if_tuple()> &> get(tuple &t) noexcept { constexpr size_t idx { indexof() }; auto &ret { val(t) }; return ret; } template inline enable_if_tuple()> &> get(tuple &t, tuple_value_type()> &def) noexcept { auto &ret { get(t) }; return defined(json::value(ret))? ret : def; } template inline enable_if_tuple()> &> get(const tuple &t) noexcept { return get(t); } template inline enable_if_tuple()>> get(const tuple &t, const tuple_value_type()> &def) noexcept { return get(t, def); } template inline enable_if_tuple()>> get(tuple &t) noexcept { return get(t); } template inline enable_if_tuple()>> get(tuple &t, tuple_value_type()> &def) noexcept { return get(t, def); } template inline enable_if_tuple get(const tuple &t, const string_view &name, R ret) noexcept { until(t, [&name, &ret] (const auto &key, auto&& val) noexcept { if constexpr(std::is_assignable()) { if(key == name) { ret = val; return false; } else return true; } else return true; }); return ret; } } // namespace json } // namespace ircd