userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
type_traits.hpp
1
#
pragma
once
2
3
#
include
<
iosfwd
>
4
#
include
<
tuple
>
5
#
include
<
type_traits
>
6
7
#
include
<
userver
/
utils
/
meta
.
hpp
>
8
9
#
include
<
userver
/
storages
/
postgres
/
detail
/
is_decl_complete
.
hpp
>
10
#
include
<
userver
/
storages
/
postgres
/
io
/
io_fwd
.
hpp
>
11
#
include
<
userver
/
storages
/
postgres
/
io
/
traits
.
hpp
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
storages::
postgres
::
io
::
traits
{
16
17
template
<
bool
Value>
18
using
BoolConstant = std::bool_constant<Value>;
19
template
<std::size_t Value>
20
using
SizeConstant = std::integral_constant<std::size_t, Value>;
21
22
///@{
23
/** @name Type mapping traits */
24
/// @brief Detect if the C++ type is mapped to a Postgres system type.
25
template
<
typename
T>
26
concept
IsMappedToSystemType
= utils::IsDeclComplete<
CppToSystemPg
<T>>::value;
27
28
/// @brief Detect if the C++ type is mapped to a Postgres user type.
29
template
<
typename
T>
30
concept
IsMappedToUserType
= utils::IsDeclComplete<
CppToUserPg
<T>>::value;
31
32
namespace
detail {
33
34
template
<
typename
Container>
35
constexpr
bool
EnableContainerMapping()
noexcept
;
36
37
}
// namespace detail
38
39
/// @brief Detect if the C++ type is mapped to a Postgres array type.
40
template
<
typename
T>
41
concept
IsMappedToArray
= detail::EnableContainerMapping<T>();
42
43
/// @brief Detect if the C++ type is mapped to a Postgres type.
44
template
<
typename
T>
45
struct
IsMappedToPg
: BoolConstant<
IsMappedToUserType
<T> ||
IsMappedToSystemType
<T> ||
IsMappedToArray
<T>> {};
46
template
<
typename
T>
47
concept
kIsMappedToPg
=
IsMappedToPg
<T>::value;
// NOLINT(readability-identifier-naming)
48
49
/// @brief Mark C++ mapping a special case for disambiguation.
50
template
<
typename
T>
51
struct
IsSpecialMapping
: std::false_type {};
52
///@}
53
54
///@{
55
/** @name Traits for containers */
56
/// @brief Mark C++ container type as supported by the driver.
57
template
<
typename
T>
58
struct
IsCompatibleContainer
: std::false_type {};
59
template
<
typename
T>
60
concept
kIsCompatibleContainer
=
IsCompatibleContainer
<T>::value;
// NOLINT(readability-identifier-naming)
61
/// @}
62
63
///@{
64
/// @brief Calculate number of dimensions in C++ container.
65
template
<
typename
T>
66
struct
DimensionCount
: SizeConstant<0> {};
67
68
template
<
kIsCompatibleContainer
T>
69
struct
DimensionCount
<T> : SizeConstant<1 +
DimensionCount
<
typename
T::value_type>::value> {};
70
template
<
typename
T>
71
inline
constexpr
std::size_t kDimensionCount = DimensionCount<T>::value;
72
///@}
73
74
///@{
75
/// @brief Detect type of multidimensional C++ container.
76
template
<
typename
T>
77
struct
ContainerFinalElement
;
78
79
namespace
detail {
80
81
template
<
typename
T>
82
struct
FinalElementImpl {
83
using
type = T;
84
};
85
86
template
<
typename
T>
87
struct
ContainerFinalElementImpl {
88
using
type =
typename
ContainerFinalElement
<
typename
T::value_type>::type;
89
};
90
91
}
// namespace detail
92
93
template
<
typename
T>
94
struct
ContainerFinalElement
95
: std::conditional_t<
kIsCompatibleContainer
<T>, detail::ContainerFinalElementImpl<T>, detail::FinalElementImpl<T>> {
96
};
97
98
template
<
typename
T>
99
using
ContainerFinaleElementType =
typename
ContainerFinalElement
<T>::type;
100
///@}
101
102
namespace
detail {
103
104
template
<
typename
Container>
105
constexpr
bool
EnableContainerMapping()
noexcept
{
106
if
constexpr
(!
traits
::
kIsCompatibleContainer
<Container>) {
107
return
false
;
108
}
else
{
109
return
traits
::
kIsMappedToPg
<
typename
traits
::
ContainerFinalElement
<Container>::type>;
110
}
111
}
112
113
}
// namespace detail
114
115
template
<
typename
T>
116
concept
CanReserve
=
requires
(T value) { value.reserve(std::size_t{1}); };
117
118
template
<
typename
T>
119
concept
CanResize
=
requires
(T value) { value.resize(std::size_t{1}); };
120
121
template
<
typename
T>
122
concept
CanClear
=
requires
(T value) { value.clear(); };
123
124
template
<
typename
T>
125
auto
Inserter(T& container) {
126
return
meta::Inserter(container);
127
}
128
129
template
<
typename
T>
130
struct
RemoveTupleReferences
;
131
132
template
<
typename
... T>
133
struct
RemoveTupleReferences
<std::tuple<T...>> {
134
using
type = std::tuple<std::remove_reference_t<T>...>;
135
};
136
137
template
<
typename
T>
138
struct
IsTupleOfRefs
: std::false_type {};
139
template
<
typename
... T>
140
struct
IsTupleOfRefs
<std::tuple<T&...>> : std::true_type {};
141
142
template
<
typename
T>
143
struct
AddTupleConstRef
;
144
145
template
<
typename
... T>
146
struct
AddTupleConstRef
<std::tuple<T...>> {
147
using
type = std::tuple<
const
std::remove_reference_t<T>&...>;
148
};
149
150
template
<
typename
Tuple>
151
struct
TupleHasParsers
;
152
153
template
<
typename
... T>
154
struct
TupleHasParsers
<std::tuple<T...>> : std::bool_constant<(
HasParser
<std::remove_cvref_t<T>> && ...)> {};
155
156
template
<
typename
Tuple>
157
struct
TupleHasFormatters
;
158
159
template
<
typename
... T>
160
struct
TupleHasFormatters
<std::tuple<T...>> : std::bool_constant<(
HasFormatter
<std::remove_cvref_t<T>> && ...)> {};
161
162
}
// namespace storages::postgres::io::traits
163
164
USERVER_NAMESPACE_END
userver
storages
postgres
io
type_traits.hpp
Generated on
for userver by
Doxygen
1.17.0