c++ - How to invoke variadic template version of ctor of boost::thread? -


below codes failed pass compilation of command g++ -std=c++11 a.cpp -wall -lboost_thread -lboost_system, if amount of arguments of callback exceeds 9, in example, when try_variadic defined.

#include <iostream> #include <boost/thread.hpp>  void foo(void) {}  template <typename t, typename... argts> void foo(t a0, argts ...args) {     std::cout << a0 << std::endl;     foo(args...); }  int main(int argc, char *argv[]) { #if try_variadic     boost::thread t(foo<int, int, int, int, int, int, int, int, int, int>, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); #else     boost::thread t(foo<int, int, int, int, int, int, int, int, int>, 1, 2, 3, 4, 5, 6, 7, 8, 9); #endif     t.join();     return 0; } 

the variadic version of ctor of boost::thread allows more 9 arguments, don't know how make compiler choose it. suggestions, hints, examples highly appreciated. thanks. :-)

i don't think it's possible. according thread docs:

thread constructor arguments

 template <class f,class a1,class a2,...>  thread(f f,a1 a1,a2 a2,...); 

...

note:

currently 9 additional arguments a1 a9 can specified in addition function f.

you wrap 'em in std::tuple. or, since you're on compiler supports variadic templates, use std::thread.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -