1 #ifndef LIBJMMCG_CORE_UNORDERED_TUPLE_HPP
2 #define LIBJMMCG_CORE_UNORDERED_TUPLE_HPP
26 #include "frozen/unordered_map.h"
41 template<
class>
class ExtractHash,
47 size=
sizeof...(MappedTypes)
49 BOOST_MPL_ASSERT_RELATION(size, >, 0);
52 using mapped_buffer_element=
std::uint8_t;
54 tmp_max_size=varadic_max(
sizeof(MappedTypes)...),
55 mapped_elem_stride=((tmp_max_size+
sizeof(
std::uint64_t))/
sizeof(
std::uint64_t))*
sizeof(
std::uint64_t),
60 BOOST_MPL_ASSERT_RELATION(mapped_elem_stride%
sizeof(std::uint64_t), ==, 0);
69 using mapped_index_colln=frozen::unordered_map<
76 class idx_for_mapped_index_colln;
77 template<std::size_t... Indices>
78 class idx_for_mapped_index_colln<std::index_sequence<Indices...>> final {
80 static constexpr typename mapped_index_colln::const_iterator
81 find(
typename mapped_index_colln::key_type key)
noexcept(
true) {
82 typename mapped_index_colln::const_iterator
const iter=mapped_indices.find(key);
83 assert(iter!=mapped_indices.end());
89 ALIGN_TO_L1_CACHE static inline constexpr const mapped_index_colln mapped_indices={
90 {ExtractHash<MappedTypes>::value, Indices*mapped_elem_stride}...
93 using mapped_index_colln_t=idx_for_mapped_index_colln<std::make_index_sequence<size>>;
96 using mapped_cont_t=
std::array<mapped_buffer_element, mapped_elem_stride*
size>;
98 objs_size=(0+...+
sizeof(MappedTypes))
100 BOOST_MPL_ASSERT_RELATION(
static_cast<std::size_t>(objs_size), <=,
static_cast<std::size_t>(max_size));
108 template<
class MappedType1,
class... MappedTypes1>
109 struct ctors_t
final {
110 template<
class MappedCtorArg,
class... MappedCtorArgs>
112 result(
typename mapped_cont_t::pointer ptr, MappedCtorArg &&arg, MappedCtorArgs &&...args)
noexcept(
113 noexcept(MappedType1(std::forward<MappedCtorArg>(arg)))
115 noexcept(ctors_t<MappedTypes1...>::result(ptr+mapped_elem_stride, std::forward<MappedCtorArgs>(args)...))
117 BOOST_MPL_ASSERT((
std::is_base_of<mapped_type, MappedType1>));
118 new (ptr) MappedType1(
std::forward<MappedCtorArg>(arg));
119 ctors_t<MappedTypes1...>::result(ptr+mapped_elem_stride,
std::forward<MappedCtorArgs>(args)...);
122 template<
class MappedType1>
123 struct ctors_t<MappedType1>
final {
124 template<
class MappedCtorArg>
125 static void result(
typename mapped_cont_t::pointer ptr, MappedCtorArg &&arg)
noexcept(
noexcept(MappedType1(std::forward<MappedCtorArg>(arg)))) {
126 BOOST_MPL_ASSERT((
std::is_base_of<mapped_type, MappedType1>));
127 new (ptr) MappedType1(
std::forward<MappedCtorArg>(arg));
131 template<
class MappedType1,
class... MappedTypes1>
132 struct default_ctors_t
final {
134 result(
typename mapped_cont_t::pointer ptr)
noexcept(
135 noexcept(MappedType1())
136 ||
noexcept(default_ctors_t<MappedTypes1...>::result(ptr+mapped_elem_stride))
138 BOOST_MPL_ASSERT((
std::is_base_of<mapped_type, MappedType1>));
139 new (ptr) MappedType1();
140 default_ctors_t<MappedTypes1...>::result(ptr+mapped_elem_stride);
143 template<
class MappedType1>
144 struct default_ctors_t<MappedType1>
final {
146 result(
typename mapped_cont_t::pointer ptr)
noexcept(
noexcept(MappedType1())) {
147 BOOST_MPL_ASSERT((
std::is_base_of<mapped_type, MappedType1>));
148 new (ptr) MappedType1();
153 using key_type=
typename mapped_index_colln::key_type;
154 using mapped_type=MappedType;
164 class... MappedCtorArgs,
178 constexpr mapped_type
const &
operator[](
const key_type key)
const noexcept(
true);
187 constexpr mapped_type &
operator[](
const key_type key)
noexcept(
true);
191 template<
class MappedType1,
class... MappedTypes1>
193 static void result(
typename mapped_cont_t::pointer ptr)
noexcept(
true) {
194 MappedType1 * obj_ctord=
reinterpret_cast<MappedType1 *>(ptr);
196 obj_ctord->~MappedType1();
199 dtors<MappedTypes1...>::result(ptr+mapped_elem_stride);
202 template<
class MappedType1>
203 struct dtors<MappedType1>
final {
204 static void result(
typename mapped_cont_t::pointer ptr)
noexcept(
true) {
205 MappedType1 * obj_ctord=
reinterpret_cast<MappedType1 *>(ptr);
207 obj_ctord->~MappedType1();