My function calls a Python function with a set of given input arguments (variadic) and returns a tuple containing the function's output (variadic because output varies on the function called).
I'm compiling on a Windows 10 machine via MinGW-w64 compiler's port of g++ using C++11. I've declared this templated variadic function (and call it) as follows:
// Declaration (in PyInterface.h)
template <typename... Inputs, typename... Outputs>
const std::tuple<Outputs...>& callFunction(const std::string &modulePath, const std::string &funcName, Inputs&&... args) {
// Calls a Python function & packs output variables into a std::tuple...
}
// Sample call (in main.cpp)
const std::tuple<std::string, std::string> output = pi.callFunction(myModulePath, myFuncName, inputArg1, inputArg2, inputArg3);
However, this error is thrown (shortened with ... for readability):
conversion from 'const std::tuple<>' to non-scalar type 'const std::tuple<std::__cxx11::basic_string<...>, std::__cxx11::basic_string<...> >' requested
As far as I'm aware using two variadic templates is legal. Additionally, it seems to me that the return type is explicitly set by the variable (const std::tuple<std::string, std::string> output) I am attempting to assign the result of the function to, so the compiler should know what the desired return
type is.
Originally, I thought that the error simply indicated that I wasn't using the variadic templates appropriately. I tried using nested template parameters (illustrated here) to specify the return type (i.e., const T<Outputs...>& callFunction). However, this only succeeded in producing an error message indicating that template deduction of T had failed.
This error indicates that my intuition is wrong and that, in my original function, the compiler isn't deducing the desired return type from output's type.
Why is my intuition wrong? How do I correctly use a variadic template to specify this function's return type?
Outputsso there are none. - NathanOliverOutputs? I already tried to modify my call topi.callFunction<std::string>, but I couldn't figure out what the error message meant:error: cannot bind 'const string {aka const std::__cxx11::basic_string<char>}' lvalue to 'std::__cxx11::basic_string<char>&&'- Vladislav Martinstringas an Input type. You get an rvalue reference with that is combined with the function argument declarationInputs &&. You are passing an lvalue ofconst stringwhich would at least require removal of theconstbefore it could be used. Besides the answer I gave where the Input types are picked up implicitly, you could explicitly specifyconst string &as an Input type, which remains aconst string &when combined withInputs &&. - Khouri Giordano