We needed to implement a callback from c++. This callback is passed as a std::function to a method.
I found an answer from @Flexo in StackOverflow that provides a std_function.i to solve this problem:
/a/32668302/22752295
My .i file contains the following lines:
%include "std_function.i" %std_function(OnStart, void, int64_t);
Everything seems fine while generating the code, however, when I try to compile this from Android Studio, I get the following error:
** error: no viable conversion from ‘SwigValueWrapper<std::function<void (long long)>>’ to ‘base::Util::OnStart’ (aka ‘function<void (long)>’).**
If I take a look at the generated code, it seems like SWIG is generating a SwigValueWrapper.
_SwigValueWrapper< std::function< void (long long) > > arg2 ;_
Everything seems to compile, including setting the actual function to this wrapper:
arg2 = *argp2;
However, this line is the one failing:
(arg1)->set_callback(arg2);
It seems like there is no possible conversion from SwigValueWrapper<std::function<void (long long)>> to std::function<void (long long).
I tried %feature(“novaluewrapper”) but I couldn’t get it to work for this example.
Is there a way to disable the use of SwigValueWrapper or prevent this error from happening?
David Franco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.