From 8933209df44b7f5fecd9a0af478992e06034ac6f Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Wed, 15 Nov 2023 21:35:23 +0200 Subject: [PATCH] Operators for user-defined functions --- dev/function.h | 5 +++++ include/sqlite_orm/sqlite_orm.h | 6 ++++++ tests/static_tests/operators_adl.cpp | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/dev/function.h b/dev/function.h index f8cd7efe3..469423f93 100644 --- a/dev/function.h +++ b/dev/function.h @@ -7,6 +7,7 @@ #include "functional/cxx_universal.h" #include "functional/cxx_type_traits_polyfill.h" +#include "tags.h" namespace sqlite_orm { @@ -86,6 +87,10 @@ namespace sqlite_orm { args_tuple args; }; + template + SQLITE_ORM_INLINE_VAR constexpr bool + is_operator_argument_v>> = true; + template struct unpacked_arg { using type = T; diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 6006bb768..ff98d125e 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -10865,6 +10865,8 @@ namespace sqlite_orm { // #include "functional/cxx_type_traits_polyfill.h" +// #include "tags.h" + namespace sqlite_orm { struct arg_values; @@ -10943,6 +10945,10 @@ namespace sqlite_orm { args_tuple args; }; + template + SQLITE_ORM_INLINE_VAR constexpr bool + is_operator_argument_v>> = true; + template struct unpacked_arg { using type = T; diff --git a/tests/static_tests/operators_adl.cpp b/tests/static_tests/operators_adl.cpp index 2c8a3c200..23335cf60 100644 --- a/tests/static_tests/operators_adl.cpp +++ b/tests/static_tests/operators_adl.cpp @@ -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; @@ -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::id)); runTests(get()); runTests(alias_column>(&User::id)); + runTests(func()); #ifdef SQLITE_ORM_WITH_CPP20_ALIASES runTests("a"_col); #endif