libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
unordered_tuple_impl.hpp
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright © 2017 by J.M.McGuiness, libjmmcg@hussar.me.uk
3
**
4
** This library is free software; you can redistribute it and/or
5
** modify it under the terms of the GNU Lesser General Public
6
** License as published by the Free Software Foundation; either
7
** version 2.1 of the License, or (at your option) any later version.
8
**
9
** This library is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
** Lesser General Public License for more details.
13
**
14
** You should have received a copy of the GNU Lesser General Public
15
** License along with this library; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*/
18
19
namespace
jmmcg
{
namespace
LIBJMMCG_VER_NAMESPACE
{
20
21
template
<
class
KeyType
,
class
MappedType
,
class
Hasher
,
template
<
class
>
class
ExtractHash
,
class
...
MappedTypes
>
22
inline
23
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
unordered_tuple
()
noexcept
(
noexcept
(
default_ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
())))
24
:
mapped_cont
{{}} {
25
if
constexpr
(
noexcept
(
default_ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
()))) {
26
default_ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
());
27
}
else
{
28
try
{
29
default_ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
());
30
}
catch
(...) {
31
dtors
<
MappedTypes
...>::
result
(
mapped_cont
.
data
());
32
throw
;
33
}
34
}
35
}
36
37
template
<
class
KeyType
,
class
MappedType
,
class
Hasher
,
template
<
class
>
class
ExtractHash
,
class
...
MappedTypes
>
38
template
<
class
MappedCtorArg
,
class
...
MappedCtorArgs
,
class
>
inline
39
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
unordered_tuple
(
MappedCtorArg
&&
arg
,
MappedCtorArgs
&&...
args
)
noexcept
(
noexcept
(
ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
(),
std
::
forward
<
MappedCtorArg
>(
arg
),
std
::
forward
<
MappedCtorArgs
>(
args
)...)))
40
:
mapped_cont
{{}} {
41
BOOST_MPL_ASSERT_RELATION(
size
, ==,
sizeof
...(
MappedCtorArgs
)+1);
42
if
constexpr
(
noexcept
(
ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
(),
std
::
forward
<
MappedCtorArg
>(
arg
),
std
::
forward
<
MappedCtorArgs
>(
args
)...))) {
43
ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
(),
std
::
forward
<
MappedCtorArg
>(
arg
),
std
::
forward
<
MappedCtorArgs
>(
args
)...);
44
}
else
{
45
try
{
46
ctors_t
<
MappedTypes
...>::
result
(
mapped_cont
.
data
(),
std
::
forward
<
MappedCtorArg
>(
arg
),
std
::
forward
<
MappedCtorArgs
>(
args
)...);
47
}
catch
(...) {
48
dtors
<
MappedTypes
...>::
result
(
mapped_cont
.
data
());
49
throw
;
50
}
51
}
52
}
53
54
template
<
class
KeyType
,
class
MappedType
,
class
Hasher
,
template
<
class
>
class
ExtractHash
,
class
...
MappedTypes
>
inline
55
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::~
unordered_tuple
()
noexcept
(
true
) {
56
dtors
<
MappedTypes
...>::
result
(
mapped_cont
.
data
());
57
}
58
59
template
<
class
KeyType
,
class
MappedType
,
class
Hasher
,
template
<
class
>
class
ExtractHash
,
class
...
MappedTypes
>
inline
60
constexpr
typename
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
mapped_type
const
&
61
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
operator
[](
const
key_type
mic
)
const
noexcept
(
true
) {
62
const
typename
mapped_index_colln
::
mapped_type
i
=
mapped_index_colln_t
::
find
(
mic
)->
second
;
63
mapped_type
const
&
ret
=
reinterpret_cast
<
mapped_type
const
&>(
mapped_cont
[
i
]);
64
return
ret
;
65
}
66
67
template
<
class
KeyType
,
class
MappedType
,
class
Hasher
,
template
<
class
>
class
ExtractHash
,
class
...
MappedTypes
>
inline
68
constexpr
typename
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
mapped_type
&
69
unordered_tuple
<
KeyType
,
MappedType
,
Hasher
,
ExtractHash
,
MappedTypes
...>::
operator
[](
const
key_type
mic
)
noexcept
(
true
) {
70
const
typename
mapped_index_colln
::
mapped_type
i
=
mapped_index_colln_t
::
find
(
mic
)->
second
;
71
mapped_type
&
ret
=
reinterpret_cast
<
mapped_type
&>(
mapped_cont
[
i
]);
72
return
ret
;
73
}
74
75
} }
core
unordered_tuple_impl.hpp
Generated on Tue May 11 2021 17:19:37 for libjmmcg by
1.9.2