Skip to content

Commit cb29f13

Browse files
committed
Fix for function pointers
1 parent 0312f0d commit cb29f13

File tree

1 file changed

+16
-1
lines changed
  • hdr/sqlite_modern_cpp

1 file changed

+16
-1
lines changed

hdr/sqlite_modern_cpp/log.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ namespace sqlite {
2626
Functor(std::forward<Functor1>(functor)) {}
2727
using Functor::operator();
2828
};
29+
template<class Functor>
30+
class WrapIntoFunctor: public Functor {
31+
public:
32+
template<class Functor1>
33+
WrapIntoFunctor(Functor1 &&functor):
34+
Functor(std::forward<Functor1>(functor)) {}
35+
using Functor::operator();
36+
};
37+
template<class ReturnType, class ...Arguments>
38+
class WrapIntoFunctor<ReturnType(*)(Arguments...)> {
39+
ReturnType(*ptr)(Arguments...);
40+
public:
41+
WrapIntoFunctor(ReturnType(*ptr)(Arguments...)): ptr(ptr) {}
42+
ReturnType operator()(Arguments... arguments) { return (*ptr)(std::forward<Arguments>(arguments)...); }
43+
};
2944
}
3045
template<class Handler>
3146
typename std::enable_if<!std::is_callable<Handler(const sqlite_exception&)>::value>::type
@@ -36,7 +51,7 @@ namespace sqlite {
3651
template<class ...Handler>
3752
typename std::enable_if<sizeof...(Handler)>=2>::type
3853
error_log(Handler &&...handler) {
39-
return error_log(detail::FunctorOverload<typename std::decay<Handler>::type...>(std::forward<Handler>(handler)...));
54+
return error_log(detail::FunctorOverload<detail::WrapIntoFunctor<typename std::decay<Handler>::type>...>(std::forward<Handler>(handler)...));
4055
}
4156
template<class Handler>
4257
typename std::enable_if<!std::is_callable<Handler(const sqlite_exception&)>::value>::type

0 commit comments

Comments
 (0)