2018-05-07 06:31:32 +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_INDEXOF_H
|
|
|
|
|
|
|
|
namespace ircd {
|
|
|
|
namespace json {
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t hash,
|
|
|
|
size_t i>
|
|
|
|
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
|
|
|
indexof()
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
|
|
|
return size<tuple>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t hash,
|
|
|
|
size_t i = 0>
|
|
|
|
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
|
|
|
indexof()
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
2020-08-05 03:02:06 +02:00
|
|
|
if constexpr(name_hash(key<tuple, i>()) == hash)
|
|
|
|
return i;
|
2018-05-07 06:31:32 +02:00
|
|
|
|
2020-08-05 03:02:06 +02:00
|
|
|
return indexof<tuple, hash, i + 1>();
|
2018-05-07 06:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
const char *const &name,
|
|
|
|
size_t i>
|
|
|
|
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
|
|
|
indexof()
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
|
|
|
return size<tuple>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
const char *const &name,
|
|
|
|
size_t i = 0>
|
|
|
|
constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
|
|
|
indexof()
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
|
|
|
return indexof<tuple, name_hash(name)>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
2020-08-05 03:29:11 +02:00
|
|
|
size_t i,
|
|
|
|
size_t N>
|
2018-05-07 06:31:32 +02:00
|
|
|
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
2020-08-05 03:29:11 +02:00
|
|
|
indexof(const char (&name)[N])
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
|
|
|
return size<tuple>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
2020-08-05 03:29:11 +02:00
|
|
|
size_t i = 0,
|
|
|
|
size_t N>
|
|
|
|
inline constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
|
|
|
indexof(const char (&name)[N])
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
2020-08-05 03:29:11 +02:00
|
|
|
if(_constexpr_equal(key<tuple, i>(), name))
|
|
|
|
return i;
|
2018-05-07 06:31:32 +02:00
|
|
|
|
2020-08-05 03:29:11 +02:00
|
|
|
return indexof<tuple, i + 1>(name);
|
2018-05-07 06:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t i>
|
|
|
|
constexpr typename std::enable_if<i == size<tuple>(), size_t>::type
|
|
|
|
indexof(const string_view &name)
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
|
|
|
return size<tuple>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class tuple,
|
|
|
|
size_t i = 0>
|
2020-08-05 03:29:11 +02:00
|
|
|
inline constexpr typename std::enable_if<i < size<tuple>(), size_t>::type
|
2018-05-07 06:31:32 +02:00
|
|
|
indexof(const string_view &name)
|
2019-08-15 08:16:38 +02:00
|
|
|
noexcept
|
2018-05-07 06:31:32 +02:00
|
|
|
{
|
2020-08-05 03:29:11 +02:00
|
|
|
if(name == key<tuple, i>())
|
|
|
|
return i;
|
2018-05-07 06:31:32 +02:00
|
|
|
|
2020-08-05 03:29:11 +02:00
|
|
|
return indexof<tuple, i + 1>(name);
|
2018-05-07 06:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace json
|
|
|
|
} // namespace ircd
|