Skip to content

Commit f16e63b

Browse files
authored
Merge pull request #1469 from fnc12/c++17-code-quality
Yet another round of C++17 hygiene
2 parents 1ddc3b5 + 475a796 commit f16e63b

108 files changed

Lines changed: 28621 additions & 29452 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev/alias.h

Lines changed: 147 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -20,180 +20,176 @@
2020
#include "tags.h"
2121
#include "column_pointer.h"
2222

23-
namespace sqlite_orm {
24-
25-
namespace internal {
23+
namespace sqlite_orm::internal {
2624
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
27-
template<class T>
28-
inline constexpr bool is_operator_argument_v<T, std::enable_if_t<orm_column_alias<T>>> = true;
25+
template<class T>
26+
inline constexpr bool is_operator_argument_v<T, std::enable_if_t<orm_column_alias<T>>> = true;
2927
#endif
3028

31-
/**
32-
* This is a common built-in class used for character based table aliases.
33-
* For convenience there exist public type aliases `alias_a`, `alias_b`, ...
34-
* The easiest way to create a table alias is using `"z"_alias.for_<Object>()`.
35-
*/
36-
template<class T, char A, char... X>
37-
struct recordset_alias : alias_tag {
38-
using type = T;
29+
/**
30+
* This is a common built-in class used for character based table aliases.
31+
* For convenience there exist public type aliases `alias_a`, `alias_b`, ...
32+
* The easiest way to create a table alias is using `"z"_alias.for_<Object>()`.
33+
*/
34+
template<class T, char A, char... X>
35+
struct recordset_alias : alias_tag {
36+
using type = T;
3937

40-
static std::string get() {
41-
return {A, X...};
42-
}
43-
};
38+
static std::string get() {
39+
return {A, X...};
40+
}
41+
};
4442

45-
/**
46-
* Column expression with table alias attached like 'C.ID'. This is not a column alias
47-
*/
48-
template<class T, class C>
49-
struct alias_column_t {
50-
using alias_type = T;
51-
using column_type = C;
43+
/**
44+
* Column expression with table alias attached like 'C.ID'. This is not a column alias
45+
*/
46+
template<class T, class C>
47+
struct alias_column_t {
48+
using alias_type = T;
49+
using column_type = C;
5250

53-
column_type column;
54-
};
51+
column_type column;
52+
};
5553

56-
template<class T>
57-
inline constexpr bool
58-
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of<T, alias_column_t>::value>> =
59-
true;
60-
61-
struct table_identifier;
62-
63-
/*
64-
* Encapsulates extracting the alias identifier of a non-alias.
65-
*
66-
* `extract()` always returns the empty string.
67-
* `as_alias()` is used in contexts where a table might be aliased, and the empty string is returned.
68-
* `as_qualifier()` is used in contexts where a table might be aliased, and the given table's name is returned.
69-
*/
70-
template<class T, class SFINAE = void>
71-
struct alias_extractor {
72-
static std::string extract() {
73-
return {};
74-
}
75-
76-
static std::string as_alias() {
77-
return {};
78-
}
79-
80-
template<class X = table_identifier>
81-
static const std::string& as_qualifier(const X& table) {
82-
return table.name;
83-
}
84-
};
85-
86-
/*
87-
* Encapsulates extracting the alias identifier of an alias.
88-
*
89-
* `extract()` always returns the alias identifier or CTE moniker.
90-
* `as_alias()` is used in contexts where a recordset is aliased, and the alias identifier is returned.
91-
* `as_qualifier()` is used in contexts where a table is aliased, and the alias identifier is returned.
92-
*/
93-
template<class A>
94-
struct alias_extractor<A, match_if<is_alias, A>> {
95-
static std::string extract() {
96-
std::stringstream ss;
97-
ss << A::get();
98-
return ss.str();
99-
}
100-
101-
// for column and regular table aliases -> alias identifier
102-
template<class T = A, satisfies_not<std::is_same, polyfill::detected_t<type_t, T>, A> = true>
103-
static std::string as_alias() {
104-
return alias_extractor::extract();
105-
}
54+
template<class T>
55+
inline constexpr bool
56+
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of<T, alias_column_t>::value>> = true;
57+
58+
struct table_identifier;
59+
60+
/*
61+
* Encapsulates extracting the alias identifier of a non-alias.
62+
*
63+
* `extract()` always returns the empty string.
64+
* `as_alias()` is used in contexts where a table might be aliased, and the empty string is returned.
65+
* `as_qualifier()` is used in contexts where a table might be aliased, and the given table's name is returned.
66+
*/
67+
template<class T, class SFINAE = void>
68+
struct alias_extractor {
69+
static std::string extract() {
70+
return {};
71+
}
72+
73+
static std::string as_alias() {
74+
return {};
75+
}
76+
77+
template<class X = table_identifier>
78+
static const std::string& as_qualifier(const X& table) {
79+
return table.name;
80+
}
81+
};
82+
83+
/*
84+
* Encapsulates extracting the alias identifier of an alias.
85+
*
86+
* `extract()` always returns the alias identifier or CTE moniker.
87+
* `as_alias()` is used in contexts where a recordset is aliased, and the alias identifier is returned.
88+
* `as_qualifier()` is used in contexts where a table is aliased, and the alias identifier is returned.
89+
*/
90+
template<class A>
91+
struct alias_extractor<A, match_if<is_alias, A>> {
92+
static std::string extract() {
93+
std::stringstream ss;
94+
ss << A::get();
95+
return ss.str();
96+
}
97+
98+
// for column and regular table aliases -> alias identifier
99+
template<class T = A, satisfies_not<std::is_same, polyfill::detected_t<type_t, T>, A> = true>
100+
static std::string as_alias() {
101+
return alias_extractor::extract();
102+
}
106103

107104
#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE)
108-
// for CTE monikers -> empty
109-
template<class T = A, satisfies<std::is_same, polyfill::detected_t<type_t, T>, A> = true>
110-
static std::string as_alias() {
111-
return {};
112-
}
105+
// for CTE monikers -> empty
106+
template<class T = A, satisfies<std::is_same, polyfill::detected_t<type_t, T>, A> = true>
107+
static std::string as_alias() {
108+
return {};
109+
}
113110
#endif
114111

115-
// for regular table aliases -> alias identifier
116-
template<class T = A, satisfies<is_table_alias, T> = true>
117-
static std::string as_qualifier(const table_identifier&) {
118-
return alias_extractor::extract();
119-
}
120-
};
112+
// for regular table aliases -> alias identifier
113+
template<class T = A, satisfies<is_table_alias, T> = true>
114+
static std::string as_qualifier(const table_identifier&) {
115+
return alias_extractor::extract();
116+
}
117+
};
121118

122-
/**
123-
* Used to store alias for expression
124-
*/
125-
template<class T, class E>
126-
struct as_t {
127-
using alias_type = T;
128-
using expression_type = E;
119+
/**
120+
* Used to store alias for expression
121+
*/
122+
template<class T, class E>
123+
struct as_t {
124+
using alias_type = T;
125+
using expression_type = E;
129126

130-
expression_type expression;
131-
};
127+
expression_type expression;
128+
};
132129

133-
/**
134-
* Built-in column alias.
135-
* For convenience there exist type aliases `colalias_a`, `colalias_b`, ...
136-
* The easiest way to create a column alias is using `"xyz"_col`.
137-
*/
138-
template<char A, char... X>
139-
struct column_alias : alias_tag {
140-
static std::string get() {
141-
return {A, X...};
142-
}
143-
};
130+
/**
131+
* Built-in column alias.
132+
* For convenience there exist type aliases `colalias_a`, `colalias_b`, ...
133+
* The easiest way to create a column alias is using `"xyz"_col`.
134+
*/
135+
template<char A, char... X>
136+
struct column_alias : alias_tag {
137+
static std::string get() {
138+
return {A, X...};
139+
}
140+
};
144141

145-
template<class T>
146-
struct alias_holder {
147-
using type = T;
142+
template<class T>
143+
struct alias_holder {
144+
using type = T;
148145

149-
alias_holder() = default;
150-
// CTE feature needs it to implicitly convert a column alias to an alias_holder; see `cte()` factory function
151-
alias_holder(const T&) noexcept {}
152-
};
146+
alias_holder() = default;
147+
// CTE feature needs it to implicitly convert a column alias to an alias_holder; see `cte()` factory function
148+
alias_holder(const T&) noexcept {}
149+
};
153150

154-
template<class T>
155-
inline constexpr bool
156-
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of<T, alias_holder>::value>> = true;
151+
template<class T>
152+
inline constexpr bool
153+
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of<T, alias_holder>::value>> = true;
157154

158155
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
159-
template<char A, char... X>
160-
struct recordset_alias_builder {
161-
template<class T>
162-
[[nodiscard]] consteval recordset_alias<T, A, X...> for_() const {
163-
return {};
164-
}
165-
166-
template<orm_table_reference auto t>
167-
[[nodiscard]] consteval auto for_() const {
168-
using T = auto_decay_table_ref_t<t>;
169-
return recordset_alias<T, A, X...>{};
170-
}
171-
172-
template<orm_recordset_alias auto t>
173-
[[nodiscard]] consteval auto for_() const {
174-
using T = std::remove_const_t<decltype(t)>;
175-
return recordset_alias<T, A, X...>{};
176-
}
177-
};
156+
template<char A, char... X>
157+
struct recordset_alias_builder {
158+
template<class T>
159+
[[nodiscard]] consteval recordset_alias<T, A, X...> for_() const {
160+
return {};
161+
}
162+
163+
template<orm_table_reference auto t>
164+
[[nodiscard]] consteval auto for_() const {
165+
using T = auto_decay_table_ref_t<t>;
166+
return recordset_alias<T, A, X...>{};
167+
}
168+
169+
template<orm_recordset_alias auto t>
170+
[[nodiscard]] consteval auto for_() const {
171+
using T = std::remove_const_t<decltype(t)>;
172+
return recordset_alias<T, A, X...>{};
173+
}
174+
};
178175
#endif
179176

180177
#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE)
181-
template<size_t n, char... C>
182-
SQLITE_ORM_CONSTEVAL auto n_to_colalias() {
183-
constexpr column_alias<'1' + n % 10, C...> colalias{};
184-
if constexpr (n > 10) {
185-
return n_to_colalias<n / 10, '1' + n % 10, C...>();
186-
} else {
187-
return colalias;
188-
}
178+
template<size_t n, char... C>
179+
SQLITE_ORM_CONSTEVAL auto n_to_colalias() {
180+
constexpr column_alias<'1' + n % 10, C...> colalias{};
181+
if constexpr (n > 10) {
182+
return n_to_colalias<n / 10, '1' + n % 10, C...>();
183+
} else {
184+
return colalias;
189185
}
186+
}
190187

191-
template<class T>
192-
inline constexpr bool is_builtin_numeric_column_alias_v = false;
193-
template<char... C>
194-
inline constexpr bool is_builtin_numeric_column_alias_v<column_alias<C...>> = ((C >= '0' && C <= '9') && ...);
188+
template<class T>
189+
inline constexpr bool is_builtin_numeric_column_alias_v = false;
190+
template<char... C>
191+
inline constexpr bool is_builtin_numeric_column_alias_v<column_alias<C...>> = ((C >= '0' && C <= '9') && ...);
195192
#endif
196-
}
197193
}
198194

199195
SQLITE_ORM_EXPORT namespace sqlite_orm {
@@ -455,7 +451,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
455451

456452
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
457453
/** @short Create a table alias.
458-
*
454+
*
459455
* Examples:
460456
* constexpr orm_table_alias auto z_alias = alias<'z'>.for_<User>();
461457
*/
@@ -464,7 +460,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
464460

465461
inline namespace literals {
466462
/** @short Create a table alias.
467-
*
463+
*
468464
* Examples:
469465
* constexpr orm_table_alias auto z_alias = "z"_alias.for_<User>();
470466
*/

0 commit comments

Comments
 (0)