Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into CTEs
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Nov 12, 2023
2 parents 6b0613d + 2e1916b commit 57b5097
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 148 deletions.
288 changes: 144 additions & 144 deletions dev/alias_traits.h
Original file line number Diff line number Diff line change
@@ -1,144 +1,144 @@
#pragma once

#include <type_traits> // std::remove_const, std::is_base_of, std::is_same, std::type_identity
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
#include <concepts>
#endif

#include "functional/cxx_universal.h"
#include "functional/cxx_type_traits_polyfill.h"
#include "type_traits.h"

namespace sqlite_orm {

/** @short Base class for a custom table alias, column alias or expression alias.
*/
struct alias_tag {};

namespace internal {

template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_alias_v = std::is_base_of<alias_tag, A>::value;

template<class A>
using is_alias = polyfill::bool_constant<is_alias_v<A>>;

/** @short Alias of a column in a record set, see `orm_column_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_column_alias_v =
polyfill::conjunction_v<is_alias<A>, polyfill::negation<polyfill::is_detected<type_t, A>>>;

template<class A>
using is_column_alias = is_alias<A>;

/** @short Alias of any type of record set, see `orm_recordset_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_recordset_alias_v =
polyfill::conjunction_v<is_alias<A>, polyfill::is_detected<type_t, A>>;

template<class A>
using is_recordset_alias = polyfill::bool_constant<is_recordset_alias_v<A>>;

/** @short Alias of a concrete table, see `orm_table_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_table_alias_v = polyfill::conjunction_v<
is_recordset_alias<A>,
polyfill::negation<std::is_same<polyfill::detected_t<type_t, A>, std::remove_const_t<A>>>>;

template<class A>
using is_table_alias = polyfill::bool_constant<is_table_alias_v<A>>;

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
/*
* Identity wrapper around a mapped object, facilitating uniform column pointer expressions.
*/
template<class O>
struct table_reference : std::type_identity<O> {};

template<class RecordSet>
struct decay_table_reference : std::remove_const<RecordSet> {};
template<class O>
struct decay_table_reference<table_reference<O>> : std::type_identity<O> {};
template<class O>
struct decay_table_reference<const table_reference<O>> : std::type_identity<O> {};

template<auto recordset>
using decay_table_reference_t = typename decay_table_reference<decltype(recordset)>::type;
#endif

/** @short Moniker of a CTE, see `orm_cte_moniker`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_cte_moniker_v =
#ifdef SQLITE_ORM_WITH_CTE
polyfill::conjunction_v<is_recordset_alias<A>,
std::is_same<polyfill::detected_t<type_t, A>, std::remove_const_t<A>>>;
#else
false;
#endif

template<class A>
using is_cte_moniker = polyfill::bool_constant<is_cte_moniker_v<A>>;
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<class A>
concept orm_alias = std::derived_from<A, alias_tag>;

/** @short Alias of a column in a record set.
*
* A column alias has the following traits:
* - is derived from `alias_tag`
* - must not have a nested `type` typename
*/
template<class A>
concept orm_column_alias = (orm_alias<A> && !orm_names_type<A>);

/** @short Alias of any type of record set.
*
* A record set alias has the following traits:
* - is derived from `alias_tag`.
* - has a nested `type` typename, which refers to a mapped object.
*/
template<class A>
concept orm_recordset_alias = (orm_alias<A> && orm_names_type<A>);

/** @short Alias of a concrete table.
*
* A concrete table alias has the following traits:
* - is derived from `alias_tag`.
* - has a `type` typename, which refers to another mapped object (i.e. doesn't refer to itself).
*/
template<class A>
concept orm_table_alias = (orm_recordset_alias<A> && !std::same_as<typename A::type, std::remove_const_t<A>>);

/** @short Reference of a concrete table, especially of a derived class.
*
* A concrete table reference has the following traits:
* - specialization of `table_reference`, whose `type` typename references a mapped object.
*/
template<class R>
concept orm_table_reference = polyfill::is_specialization_of_v<std::remove_const_t<R>, internal::table_reference>;

/** @short Moniker of a CTE.
*
* A CTE moniker has the following traits:
* - is derived from `alias_tag`.
* - has a `type` typename, which refers to itself.
*/
template<class A>
concept orm_cte_moniker = (orm_recordset_alias<A> && std::same_as<typename A::type, std::remove_const_t<A>>);

template<class T>
concept orm_refers_to_table = (orm_table_reference<T> || orm_table_alias<T>);

template<class T>
concept orm_refers_to_recordset = (orm_table_reference<T> || orm_recordset_alias<T>);

template<class T>
concept orm_mapped_recordset = (orm_table_reference<T> || orm_cte_moniker<T>);
#endif
}
#pragma once

#include <type_traits> // std::remove_const, std::is_base_of, std::is_same, std::type_identity
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
#include <concepts>
#endif

#include "functional/cxx_universal.h"
#include "functional/cxx_type_traits_polyfill.h"
#include "type_traits.h"

namespace sqlite_orm {

/** @short Base class for a custom table alias, column alias or expression alias.
*/
struct alias_tag {};

namespace internal {

template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_alias_v = std::is_base_of<alias_tag, A>::value;

template<class A>
using is_alias = polyfill::bool_constant<is_alias_v<A>>;

/** @short Alias of a column in a record set, see `orm_column_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_column_alias_v =
polyfill::conjunction_v<is_alias<A>, polyfill::negation<polyfill::is_detected<type_t, A>>>;

template<class A>
using is_column_alias = is_alias<A>;

/** @short Alias of any type of record set, see `orm_recordset_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_recordset_alias_v =
polyfill::conjunction_v<is_alias<A>, polyfill::is_detected<type_t, A>>;

template<class A>
using is_recordset_alias = polyfill::bool_constant<is_recordset_alias_v<A>>;

/** @short Alias of a concrete table, see `orm_table_alias`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_table_alias_v = polyfill::conjunction_v<
is_recordset_alias<A>,
polyfill::negation<std::is_same<polyfill::detected_t<type_t, A>, std::remove_const_t<A>>>>;

template<class A>
using is_table_alias = polyfill::bool_constant<is_table_alias_v<A>>;

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
/*
* Identity wrapper around a mapped object, facilitating uniform column pointer expressions.
*/
template<class O>
struct table_reference : std::type_identity<O> {};

template<class RecordSet>
struct decay_table_reference : std::remove_const<RecordSet> {};
template<class O>
struct decay_table_reference<table_reference<O>> : std::type_identity<O> {};
template<class O>
struct decay_table_reference<const table_reference<O>> : std::type_identity<O> {};

template<auto recordset>
using decay_table_reference_t = typename decay_table_reference<decltype(recordset)>::type;
#endif

/** @short Moniker of a CTE, see `orm_cte_moniker`.
*/
template<class A>
SQLITE_ORM_INLINE_VAR constexpr bool is_cte_moniker_v =
#ifdef SQLITE_ORM_WITH_CTE
polyfill::conjunction_v<is_recordset_alias<A>,
std::is_same<polyfill::detected_t<type_t, A>, std::remove_const_t<A>>>;
#else
false;
#endif

template<class A>
using is_cte_moniker = polyfill::bool_constant<is_cte_moniker_v<A>>;
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<class A>
concept orm_alias = std::derived_from<A, alias_tag>;

/** @short Alias of a column in a record set.
*
* A column alias has the following traits:
* - is derived from `alias_tag`
* - must not have a nested `type` typename
*/
template<class A>
concept orm_column_alias = (orm_alias<A> && !orm_names_type<A>);

/** @short Alias of any type of record set.
*
* A record set alias has the following traits:
* - is derived from `alias_tag`.
* - has a nested `type` typename, which refers to a mapped object.
*/
template<class A>
concept orm_recordset_alias = (orm_alias<A> && orm_names_type<A>);

/** @short Alias of a concrete table.
*
* A concrete table alias has the following traits:
* - is derived from `alias_tag`.
* - has a `type` typename, which refers to another mapped object (i.e. doesn't refer to itself).
*/
template<class A>
concept orm_table_alias = (orm_recordset_alias<A> && !std::same_as<typename A::type, std::remove_const_t<A>>);

/** @short Reference of a concrete table, especially of a derived class.
*
* A concrete table reference has the following traits:
* - specialization of `table_reference`, whose `type` typename references a mapped object.
*/
template<class R>
concept orm_table_reference = polyfill::is_specialization_of_v<std::remove_const_t<R>, internal::table_reference>;

/** @short Moniker of a CTE.
*
* A CTE moniker has the following traits:
* - is derived from `alias_tag`.
* - has a `type` typename, which refers to itself.
*/
template<class A>
concept orm_cte_moniker = (orm_recordset_alias<A> && std::same_as<typename A::type, std::remove_const_t<A>>);

template<class T>
concept orm_refers_to_table = (orm_table_reference<T> || orm_table_alias<T>);

template<class T>
concept orm_refers_to_recordset = (orm_table_reference<T> || orm_recordset_alias<T>);

template<class T>
concept orm_mapped_recordset = (orm_table_reference<T> || orm_cte_moniker<T>);
#endif
}
4 changes: 2 additions & 2 deletions dev/column_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace sqlite_orm {
}

/**
* Make table reference.
* Make a table reference.
*/
template<class O>
requires(!orm_recordset_alias<O>)
Expand All @@ -81,7 +81,7 @@ namespace sqlite_orm {
}

/**
* Make table reference.
* Make a table reference.
*/
template<class O>
requires(!orm_recordset_alias<O>)
Expand Down
4 changes: 2 additions & 2 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ namespace sqlite_orm {
}

/**
* Make table reference.
* Make a table reference.
*/
template<class O>
requires(!orm_recordset_alias<O>)
Expand All @@ -3352,7 +3352,7 @@ namespace sqlite_orm {
}

/**
* Make table reference.
* Make a table reference.
*/
template<class O>
requires(!orm_recordset_alias<O>)
Expand Down

0 comments on commit 57b5097

Please sign in to comment.