Skip to content

Commit

Permalink
Operators for user-defined functions
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Nov 15, 2023
1 parent 42999ac commit 8933209
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dev/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

namespace sqlite_orm {

Expand Down Expand Up @@ -86,6 +87,10 @@ namespace sqlite_orm {
args_tuple args;
};

template<class T>
SQLITE_ORM_INLINE_VAR constexpr bool
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of_v<T, function_call>>> = true;

template<class T>
struct unpacked_arg {
using type = T;
Expand Down
6 changes: 6 additions & 0 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10865,6 +10865,8 @@ namespace sqlite_orm {

// #include "functional/cxx_type_traits_polyfill.h"

// #include "tags.h"

namespace sqlite_orm {

struct arg_values;
Expand Down Expand Up @@ -10943,6 +10945,10 @@ namespace sqlite_orm {
args_tuple args;
};

template<class T>
SQLITE_ORM_INLINE_VAR constexpr bool
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of_v<T, function_call>>> = true;

template<class T>
struct unpacked_arg {
using type = T;
Expand Down
5 changes: 5 additions & 0 deletions tests/static_tests/operators_adl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using sqlite_orm::and_;
using sqlite_orm::c;
using sqlite_orm::colalias_a;
using sqlite_orm::column;
using sqlite_orm::func;
using sqlite_orm::get;
using sqlite_orm::or_;
using sqlite_orm::internal::and_condition_t;
Expand Down Expand Up @@ -107,11 +108,15 @@ TEST_CASE("ADL and expression operators") {
struct User {
int id;
};
struct ScalarFunction {
int operator()() const;
};

runTests(c(&User::id));
runTests(column<User>(&User::id));
runTests(get<colalias_a>());
runTests(alias_column<alias_a<User>>(&User::id));
runTests(func<ScalarFunction>());
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
runTests("a"_col);
#endif
Expand Down

0 comments on commit 8933209

Please sign in to comment.