ThinSQLite++
A thin, safe and convenient modern C++ wrapper for the SQLite API.
Toggle main menu visibility
Loading...
Searching...
No Matches
impl
meta.hpp
1
/*
2
Copyright 2019 Eugene Gershnik
3
4
Use of this source code is governed by a BSD-style
5
license that can be found in the LICENSE file or at
6
https://github.com/gershnik/thinsqlitepp/blob/master/LICENSE
7
*/
8
9
#ifndef HEADER_SQLITEPP_META_INCLUDED
10
#define HEADER_SQLITEPP_META_INCLUDED
11
12
#include "config.hpp"
13
14
#include <
memory
>
15
#include <
type_traits
>
16
#if __cpp_impl_three_way_comparison >= 201907
17
#include <
compare
>
18
#endif
19
#if __cpp_lib_bit_cast >= 201806L
20
#include <
bit
>
21
#endif
22
23
#define SQLITEPP_CALL_DETECTOR_0(name, rettype, call) \
24
private: \
25
template<class T> static constexpr bool has_##name##_impl(decltype(call()) *) \
26
{ return std::is_same_v<decltype(call()), rettype>; } \
27
template<class T> static constexpr bool has_##name##_impl(...) \
28
{ return false; } \
29
public: \
30
template<class T> static constexpr bool has_##name = has_##name##_impl<T>(nullptr); \
31
template<class T> static constexpr bool has_noexcept_##name = []() constexpr { \
32
if constexpr (has_##name<T>) \
33
return noexcept(call()); \
34
else \
35
return false; \
36
}()
37
38
#define SQLITEPP_CALL_DETECTOR(name, rettype, call, ...) \
39
private: \
40
template<class T> static constexpr bool has_##name##_impl(decltype(call(__VA_ARGS__)) *) \
41
{ return std::is_same_v<decltype(call(__VA_ARGS__)), rettype>; } \
42
template<class T> static constexpr bool has_##name##_impl(...) \
43
{ return false; } \
44
public: \
45
template<class T> static constexpr bool has_##name = has_##name##_impl<T>(nullptr); \
46
template<class T> static constexpr bool has_noexcept_##name = []() constexpr { \
47
if constexpr (has_##name<T>) \
48
return noexcept(call(__VA_ARGS__)); \
49
else \
50
return false; \
51
}()
52
53
#define SQLITEPP_STATIC_METHOD_DETECTOR_0(rettype, name) SQLITEPP_CALL_DETECTOR_0(name, rettype, T::name)
54
#define SQLITEPP_STATIC_METHOD_DETECTOR(rettype, name, ...) SQLITEPP_CALL_DETECTOR(name, rettype, T::name, __VA_ARGS__)
55
#define SQLITEPP_METHOD_DETECTOR_0(rettype, name) SQLITEPP_CALL_DETECTOR_0(name, rettype, std::declval<T>().name)
56
#define SQLITEPP_METHOD_DETECTOR(rettype, name, ...) SQLITEPP_CALL_DETECTOR(name, rettype, std::declval<T>().name, __VA_ARGS__)
57
58
59
60
namespace
thinsqlitepp
61
{
62
#if __cplusplus <= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG <= 201703L)
63
64
template
<
class
T >
struct
type_identity {
using
type = T; };
65
66
template
<
class
T >
using
type_identity_t =
typename
type_identity<T>::type;
67
68
#else
69
70
template
<
class
T >
using
type_identity = std::type_identity<T>;
71
72
template
<
class
T >
using
type_identity_t = std::type_identity_t<T>;
73
74
#endif
75
77
78
template
<
class
T,
bool
B>
79
constexpr
bool
dependent_bool = B;
80
81
template
<
class
T>
82
constexpr
bool
dependent_false = dependent_bool<T, false>;
83
84
template
<
class
T>
85
constexpr
bool
dependent_true = dependent_bool<T, true>;
86
87
88
//MARK: - strong_ordering_from_int
89
90
template
<
class
T>
91
using
size_equivalent =
92
std::conditional_t<
sizeof
(T) ==
sizeof
(
signed
char
),
signed
char,
93
std::conditional_t<
sizeof
(T) ==
sizeof
(
short
), short,
94
std::conditional_t<
sizeof
(T) ==
sizeof
(
int
), int,
95
std::conditional_t<
sizeof
(T) ==
sizeof
(
long
), long,
96
std::conditional_t<
sizeof
(T) ==
sizeof
(
long
long
),
long
long,
97
void
98
>>>>>;
99
100
#if __cpp_impl_three_way_comparison >= 201907
101
102
103
inline
std::strong_ordering strong_ordering_from_int(
int
val)
104
{
105
using
equivalent
= size_equivalent<std::strong_ordering>;
106
if
constexpr
(!
std::is_void_v<equivalent>
)
107
{
108
equivalent
eq_val =
equivalent
((val > 0) - (val < 0));
109
#if __cpp_lib_bit_cast >= 201806L
110
return
std::bit_cast<std::strong_ordering>
(eq_val);
111
#else
112
return
*(std::strong_ordering *)&eq_val;
113
#endif
114
}
115
else
116
{
117
return
val < 0 ? std::strong_ordering::less : (
118
val == 0 ? std::strong_ordering::equal : (
119
std::strong_ordering::greater
120
));
121
}
122
}
123
124
#endif
125
126
128
129
}
130
131
#endif
132
std::bit_cast
T bit_cast(T... args)
bit
compare
std::experimental::filesystem::equivalent
T equivalent(T... args)
std::is_void_v
T is_void_v
memory
thinsqlitepp
ThinSQLite++ namespace.
Definition
backup_iface.hpp:17
type_traits
Generated by
1.17.0