Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Introduced a configuration header, made universally available
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Feb 15, 2023
1 parent 99c3404 commit f30c993
Show file tree
Hide file tree
Showing 20 changed files with 1,366 additions and 1,324 deletions.
12 changes: 6 additions & 6 deletions dev/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace sqlite_orm {

namespace internal {

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
/*
* Helper class to facilitate user-defined string literal operator template
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace sqlite_orm {
alias_holder() = default;
};

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<char A, char... C>
struct table_alias_builder {
static_assert(sizeof...(C) == 0 && ((A >= 'A' && 'Z' <= A) || (A >= 'a' && 'z' <= A)),
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace sqlite_orm {
return {c};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als,
class C,
class A = std::remove_const_t<decltype(als)>,
Expand All @@ -184,7 +184,7 @@ namespace sqlite_orm {
return {std::move(expression)};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, class E, internal::satisfies<internal::is_column_alias, decltype(als)> = true>
auto as(E expression) {
return internal::as_t<std::remove_const_t<decltype(als)>, E>{std::move(expression)};
Expand All @@ -204,7 +204,7 @@ namespace sqlite_orm {
return {};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, internal::satisfies<internal::is_column_alias, decltype(als)> = true>
auto get() {
return internal::alias_holder<std::remove_const_t<decltype(als)>>{};
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace sqlite_orm {
using colalias_h = internal::column_alias<'h'>;
using colalias_i = internal::column_alias<'i'>;

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
/** @short Create aliased tables e.g. `constexpr auto z_alias = alias_<'z'>.for_<User>()`.
*/
template<char A>
Expand Down
1 change: 1 addition & 0 deletions dev/column_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "tuple_helper/tuple_filter.h"
#include "type_traits.h"
#include "member_traits/member_traits.h"
#include "mapped_type_proxy.h"
#include "core_functions.h"
#include "select_constraints.h"
#include "operators.h"
Expand Down
10 changes: 5 additions & 5 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ namespace sqlite_orm {
return {};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
/**
* Explicit FROM function. Usage:
* `storage.select(&User::id, from<"a"_alias.for_<User>>());`
Expand Down Expand Up @@ -1028,7 +1028,7 @@ namespace sqlite_orm {
return {std::move(o)};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, class O, internal::satisfies<internal::is_recordset_alias, decltype(als)> = true>
auto left_join(O o) {
return internal::left_join_t<std::remove_const_t<decltype(als)>, O>{std::move(o)};
Expand All @@ -1040,7 +1040,7 @@ namespace sqlite_orm {
return {std::move(o)};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, class O, internal::satisfies<internal::is_recordset_alias, decltype(als)> = true>
auto join(O o) {
return internal::join_t<std::remove_const_t<decltype(als)>, O>{std::move(o)};
Expand All @@ -1052,7 +1052,7 @@ namespace sqlite_orm {
return {std::move(o)};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, class O, internal::satisfies<internal::is_recordset_alias, decltype(als)> = true>
auto left_outer_join(O o) {
return internal::left_outer_join_t<std::remove_const_t<decltype(als)>, O>{std::move(o)};
Expand All @@ -1064,7 +1064,7 @@ namespace sqlite_orm {
return {std::move(o)};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, class O, internal::satisfies<internal::is_recordset_alias, decltype(als)> = true>
auto inner_join(O o) {
return internal::inner_join_t<std::remove_const_t<decltype(als)>, O>{std::move(o)};
Expand Down
8 changes: 8 additions & 0 deletions dev/functional/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "cxx_universal.h"

#if defined(SQLITE_ORM_CONCEPTS_SUPPORTED) && defined(SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED) && \
defined(SQLITE_ORM_INLINE_VARIABLES_SUPPORTED)
#define SQLITE_ORM_WITH_CPP20_ALIASES
#endif
5 changes: 5 additions & 0 deletions dev/functional/cxx_compiler_quirks.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

/*
* This header defines macros for circumventing compiler quirks on which sqlite_orm depends.
* May amend cxx_core_features.h
*/

#ifdef __clang__
#define SQLITE_ORM_DO_PRAGMA(...) _Pragma(#__VA_ARGS__)
#endif
Expand Down
5 changes: 5 additions & 0 deletions dev/functional/cxx_core_features.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

/*
* This header detects core C++ language features on which sqlite_orm depends.
* May be updated/overwritten by cxx_compiler_quirks.h
*/

#ifdef __has_cpp_attribute
#define SQLITE_ORM_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr)
#else
Expand Down
2 changes: 1 addition & 1 deletion dev/functional/cxx_universal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This header makes central C++ functionality on which sqlite_orm depends universally available:
* - alternative operator representations
* - ::size_t, ::ptrdiff_t, ::nullptr_t
* - C++ core feature macros
* - C++ core language feature macros
* - macros for dealing with compiler quirks
*/

Expand Down
3 changes: 3 additions & 0 deletions dev/get_prepared_statement.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <type_traits> // std::is_same, std::decay, std::remove_reference
#include <tuple> // std::get

#include "functional/cxx_universal.h" // ::size_t
#include "functional/static_magic.h"
#include "prepared_statement.h"
#include "ast_iterator.h"
#include "node_tuple.h"
#include "expression_object_type.h"

namespace sqlite_orm {
Expand Down
2 changes: 1 addition & 1 deletion dev/select_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ namespace sqlite_orm {
return {definedOrder};
}

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<auto als, internal::satisfies<internal::is_recordset_alias, decltype(als)> = true>
auto asterisk(bool definedOrder = false) {
return internal::asterisk_t<std::remove_const_t<decltype(als)>>{definedOrder};
Expand Down
2 changes: 1 addition & 1 deletion examples/column_aliases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void marvel_hero_ordered_by_o_pos() {
}
}
cout << endl;
#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
{
// SELECT name, instr(abilities, 'o') i
// FROM marvel
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_aliases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main(int, char** argv) {
// SELECT C.ID, C.NAME, C.AGE, D.DEPT
// FROM COMPANY AS C, DEPARTMENT AS D
// WHERE C.ID = D.EMP_ID;
#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr auto c_als = "c"_alias.for_<Employee>();
constexpr auto d = "d"_alias.for_<Department>();
static_assert(std::is_empty_v<EmployeeIdAlias>);
Expand Down
2 changes: 1 addition & 1 deletion examples/exists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ int main(int, char**) {
// )
// ORDER BY 'c'."PAYMENT_AMT"

#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr auto c_als = "c"_alias.for_<Customer>();
constexpr auto d = "d"_alias.for_<Customer>();

Expand Down
4 changes: 2 additions & 2 deletions examples/self_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int main() {
// FROM employees
// INNER JOIN employees m
// ON m.ReportsTo = employees.EmployeeId
#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr auto m = "m"_alias.for_<Employee>();
auto firstNames = storage.select(columns(m->*&Employee::firstName || c(" ") || m->*&Employee::lastName,
&Employee::firstName || c(" ") || &Employee::lastName),
Expand Down Expand Up @@ -230,7 +230,7 @@ int main() {
// FROM employees
// INNER JOIN employees emp
// ON emp.ReportsTo = employees.EmployeeId
#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
static_assert(std::is_empty_v<custom_alias<Employee>>);
constexpr auto emp = custom_alias<Employee>{};
auto firstNames = storage.select(columns(emp->*&Employee::firstName || c(" ") || emp->*&Employee::lastName,
Expand Down
2 changes: 1 addition & 1 deletion examples/subquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ int main(int, char**) {
// WHERE salary >(SELECT AVG(salary)
// FROM employees
// WHERE department_id = e.department_id);
#ifdef SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr auto e = "e"_alias.for_<Employee>();
auto rows = storage.select(
columns(e->*&Employee::lastName, e->*&Employee::salary, e->*&Employee::departmentId),
Expand Down
Loading

0 comments on commit f30c993

Please sign in to comment.