c++ - 'va_start' used in function with fixed args error -
my nullpointcheck function:
template<typename t, typename... args> bool __nullpointcheck(t first, args... args) {     bool ret = true;     va_list vl;     auto n = sizeof...(args);     va_start(vl, n);     (auto = 0; <= n; ++i)     {         auto p = va_arg(vl, t);         if (!p)         {             ret = false;         }     }     va_end(vl);     return ret; } but i'm getting ndk build error follows:
'va_start' used in function fixed args va_start(vl, n); when change second param in va_start first follows:
va_start(vl, first); ndk-build export error follows:
     'va_start' used in function fixed args     va_start(vl, first);     ^ e:/android_home/android-ndk-r10c/toolchains/llvm-3.5/prebuilt/windows-x86_64/bin \..\lib\clang\3.5\include\stdarg.h:33:29: note: expanded macro 'va_start' #define va_start(ap, param) __builtin_va_start(ap, param) there no errors in vs2013, code can's pass ndk-build stage
va_start etc. can used in function prototype ends in ...); . different parameter pack. code uses parameter pack. syntax using parameter packs different syntax variadic functions.
i assuming function should return true if , if arguments non-null pointers. 1 way implement function be:
inline constexpr bool nullpointcheck() { return true; }  template<typename t, typename... args> constexpr bool nullpointcheck(t&& first, args&&... args) {     return first && nullpointcheck(args...); } rontgen's answer good.
you can use function check if arbitrary argument list true. used universal references copies not made of arguments; makes no difference pointers may make difference more complicated types.
to limit function accept pointers, change t&& t *. (leave args&& is).  if want accept literal nullptr need overload:
inline constexpr bool nullpointcheck(std::nullptr_t) { return false; } because nullptr not deduce t *.
Comments
Post a Comment