Skip to content

Commit 1560250

Browse files
authored
Merge pull request #101 from zauguin/funcPtr
Support function pointers as callbacks
2 parents 4116179 + e2d1624 commit 1560250

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

hdr/sqlite_modern_cpp/utility/function_traits.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ namespace sqlite {
2020
>
2121
struct function_traits<
2222
ReturnType(ClassType::*)(Arguments...) const
23-
> {
24-
typedef ReturnType result_type;
25-
26-
template <std::size_t Index>
27-
using argument = typename std::tuple_element<
28-
Index,
29-
std::tuple<Arguments...>
30-
>::type;
31-
32-
static const std::size_t arity = sizeof...(Arguments);
33-
};
23+
> : function_traits<ReturnType(*)(Arguments...)> { };
3424

3525
/* support the non-const operator ()
3626
* this will work with user defined functors */
@@ -41,6 +31,14 @@ namespace sqlite {
4131
>
4232
struct function_traits<
4333
ReturnType(ClassType::*)(Arguments...)
34+
> : function_traits<ReturnType(*)(Arguments...)> { };
35+
36+
template <
37+
typename ReturnType,
38+
typename... Arguments
39+
>
40+
struct function_traits<
41+
ReturnType(*)(Arguments...)
4442
> {
4543
typedef ReturnType result_type;
4644

tests/functions.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using namespace sqlite;
66
using namespace std;
77

8+
int add_integers(int i, int j) {
9+
return i+j;
10+
}
811
int main()
912
{
1013
try
@@ -13,7 +16,7 @@ int main()
1316

1417
db.define("my_new_concat", [](std::string i, std::string j) {return i+j;});
1518
db.define("my_new_concat", [](std::string i, std::string j, std::string k) {return i+j+k;});
16-
db.define("add_integers", [](int i, int j) {return i+j;});
19+
db.define("add_integers", &add_integers);
1720
std::string test1, test3;
1821
int test2 = 0;
1922
db << "select my_new_concat('Hello ','world!')" >> test1;

0 commit comments

Comments
 (0)