2018-05-20 02:33:28 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// 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_KEY_H
|
|
|
|
|
|
|
|
namespace ircd {
|
|
|
|
namespace json {
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t i>
|
2019-05-17 07:16:30 +02:00
|
|
|
constexpr enable_if_tuple<tuple, const char *>
|
2018-05-20 02:33:28 +02:00
|
|
|
key()
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-20 02:33:28 +02:00
|
|
|
{
|
|
|
|
return tuple_element<tuple, i>::key;
|
|
|
|
}
|
|
|
|
|
2020-08-06 03:16:16 +02:00
|
|
|
template<size_t i,
|
|
|
|
class tuple>
|
2022-07-13 00:46:14 +02:00
|
|
|
inline constexpr enable_if_tuple<tuple, const char *>
|
2020-08-06 03:16:16 +02:00
|
|
|
key(const tuple &t)
|
|
|
|
noexcept
|
|
|
|
{
|
2022-06-26 23:18:13 +02:00
|
|
|
return prop<i>(t).key;
|
2020-08-06 03:16:16 +02:00
|
|
|
}
|
|
|
|
|
2018-05-20 02:33:28 +02:00
|
|
|
template<class tuple,
|
|
|
|
size_t i>
|
2022-07-13 00:46:14 +02:00
|
|
|
inline constexpr typename std::enable_if<i == tuple::size(), const char *>::type
|
2018-05-20 02:33:28 +02:00
|
|
|
key(const size_t &j)
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-20 02:33:28 +02:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t i = 0>
|
2022-07-13 00:46:14 +02:00
|
|
|
inline constexpr typename std::enable_if<i < tuple::size(), const char *>::type
|
2018-05-20 02:33:28 +02:00
|
|
|
key(const size_t &j)
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-20 02:33:28 +02:00
|
|
|
{
|
2020-08-06 03:16:16 +02:00
|
|
|
if(likely(j != i))
|
|
|
|
return key<tuple, i + 1>(j);
|
2018-05-20 02:33:28 +02:00
|
|
|
|
2020-08-06 03:16:16 +02:00
|
|
|
return tuple_element<tuple, i>::key;
|
2018-05-20 02:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace json
|
|
|
|
} // namespace ircd
|