Send variadic template pack to C-function variadic macros

  android-ndk, c++, visual-studio

I have set of actions:

  1. Call variadic template function
  2. Call variadic template function recursive, which unpack variadic parameters and create of them std::tuple (with modify, but in example I block this functional)
  3. Call std::apply with std::tuple, which get new variadic template pack
  4. Call other variadic template function with new variadic template pack
  5. Call C-function variadic macros and send new variadic template pack

My code:

void testFunc(...)
{

}

template<class ...Args>
void test2(const std::string& nc, const std::string& nm, const std::string& sig, Args ...args)
{
    testFunc(args...);
}

template<class T>
auto _test1(T& first)
{
    // TODO: cast types (blocked functional)
    auto t = std::make_tuple(first);
    return t;
}

template<class First, class ...Args>
auto _test1(First first, Args ...args)
{
    auto t = std::tuple_cat(std::make_tuple(first), _test1(args...));
    return t;
}


template<class ...Args>
void test1(const std::string& nc, const std::string& nm, const std::string& sig, Args ...args)
{
    auto t = _test1(nc, nm, args...);
    std::apply([&nc, &nm, &sig](auto &&...a)
        {
            test2(nc, nm, sig, a...);
        },
        t);
}

int main()
{
    test1("asdasdas", "asdasdasdas", "dasdas", 45, 96.23, "asdasdas", 886);
}

Code works successfully, but on compiler MSVS 2019. Compiler Cland in Android Studio print a error:

error: cannot pass object of non-trivial type 'std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >' through variadic function; call will abort at runtime [-Wnon-pod-varargs]

Line error:

testFunc(args...);

How fix it?

P.S.:
Terms: I can’t edit signature function void testFunc(...)

Source: Windows Questions C++

LEAVE A COMMENT