id summary reporter owner description type status milestone component version severity resolution keywords cc 9303 packaged_task does not compile using c++03 and Cmake 2.8.9 e66a5b10@… viboes "Setup consists of client(s), a server, and device(s). A client interacts with a device by sending requests to the server. These requests are examined and routed to the appropriate device. Requests are handled asynchronously, and are occasionally queued up via boost::asio::io_service::strand for various reasons. It appears as if packaged_task has a few different templates to choose from: packaged_task packaged_task packaged_task To ensure that I was using the function correctly, I started simple; using the simple example on the boost::futures page as a starting point. From there, I created four simple functions: int return, no parameters. int return, with parameters. std::string return, no parameters. std::string return, with parameters. Test functions {{{ std::string ans(""forty two""); int int_no_params() { return 42; } int int_with_params(int param) { return param; } std::string string_no_params() { return std::string(""forty two""); } std::string string_with_params(std::string & param) // Have tried both with and without '&' { return param; } }}} EXAMPLE 1: {{{ int function(void) //! Compiles and produces correct result. { boost::packaged_task example(int_no_params); boost::future f = example.get_future(); boost::thread task(boost::move(example)); int answer = f.get(); std::cout << ""Answer to life and whatnot, in English: "" << answer << std::endl; task.join(); } }}} EXAMPLE 2: {{{ std::string function(void) //! Compiles and produces correct result. { boost::packaged_task example(string_no_params); boost::future f = example.get_future(); boost::thread task(boost::move(example)); std::string answer = f.get(); std::cout << ""string_no_params: "" << answer << std::endl; task.join(); } }}} EXAMPLE 3: {{{ std::string(std::string& param) No threading //! Doesn't compile. //! error: variable ‘boost::packaged_task(std::basic_string&)> example’ has initializer but incomplete type { boost::packaged_task example(string_with_params); boost::future f = example.get_future(); example(ans); std::string answer = f.get(); std::cout << ""string_with_params: "" << answer << std::endl; } }}} EXAMPLE 4: {{{ using boost::threading //! Doesn't compile. //! error: variable ‘boost::packaged_task(std::basic_string&)> example’ has initializer but incomplete type { boost::packaged_task example(string_with_params); boost::future f = example.get_future(); boost::thread task(boost::move(example), ans); std::string answer = f.get(); std::cout << ""string_with_params: "" << answer << std::endl; task.join(); } }}} EXAMPLE 5: {{{ //Using extended initializers in packaged_task declaration //! Doesn't compile in C++03, C++11 only. //! error: extended initializer lists only available with -std=c++11 or -std=gnu++11 [-Werror] { boost::packaged_task example { boost::bind(&string_with_params, ans) }; boost::future f = example.get_future(); boost::thread task(boost::move(example), ans); std::string answer = f.get(); std::cout << ""string_with_params: "" << answer << std::endl; task.join(); } }}} EXAMPLE 6: {{{ //Threaded, using shared_ptr //The following use typedef boost::packaged_task task_t; //Because packaged tasks can't be copied, binding //shared_ptr::operator() to task was a suggested solution found on stackoverflow. // error: invalid use of incomplete type ‘class boost::packaged_task(std::basic_string&)>’ // error: incomplete type ‘task_t {aka boost::packaged_task(std::basic_string&)>}’ used in nested name specifier // boost/thread/future.hpp:1320:11: error: declaration of ‘class boost::packaged_task(std::basic_string&)>’ { boost::shared_ptr example = boost::make_shared(boost::bind(&string_with_params, ans)); boost::future f = example->get_future(); boost::thread task(boost::bind(&task_t::operator(), example)); std::string answer = f.get(); std::cout << ""string_with_params: "" << answer << std::endl; task.join(); } }}} EXAMPLE 7: {{{ //Using boost::asio::io_service and boost::bind // error: invalid use of incomplete type ‘class boost::packaged_task(std::basic_string&)>’ // error: incomplete type ‘task_t {aka boost::packaged_task(std::basic_string&)>}’ used in nested name specifier // boost/thread/future.hpp:1320:11: error: declaration of ‘class boost::packaged_task(std::basic_string&)>’ { boost::asio::io_service io_service; boost::thread_group threads; boost::asio::io_service::work work(io_service); for (int i = 0; i < 3; ++i) { threads.create_thread(boost::bind(&boost::asio::io_service::run, &io_service)); } boost::shared_ptr example = boost::make_shared(boost::bind(&string_with_params, ans)); boost::future f = example->get_future(); io_service.post(boost::bind(&task_t::operator(), example)); std::string answer = f.get(); std::cout << ""string_with_params: "" << answer << std::endl; threads.join_all(); } }}} It seems like future.hpp has a problem that is preventing the proper template from being used." Bugs closed thread Boost 1.54.0 Problem worksforme packaged_task, bind, asio