Subject: [Boost-bugs] [Boost C++ Libraries] #9303: packaged_task<R(Argtypes)> does not compile using c++03 and Cmake 2.8.9
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-10-25 18:21:47
#9303: packaged_task<R(Argtypes)> does not compile using c++03 and Cmake 2.8.9
---------------------------------------+----------------------
Reporter: e66a5b10@⦠| Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.54.0 | Severity: Problem
Keywords: packaged_task, bind, asio |
---------------------------------------+----------------------
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<R>
packaged_task<R()>
packaged_task<R(ArgTypes)>
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<int()> example(int_no_params);
boost::future<int> 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<std::string()> example(string_no_params);
boost::future<std::string> 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<char>(std::basic_string<char>&)>
exampleâ has initializer but incomplete type
{
boost::packaged_task<std::string(std::string&)>
example(string_with_params);
boost::future<std::string> 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<char>(std::basic_string<char>&)>
exampleâ has initializer but incomplete type
{
boost::packaged_task<std::string(std::string&)>
example(string_with_params);
boost::future<std::string> 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<std::string(std::string&)> example
{ boost::bind(&string_with_params, ans) };
boost::future<std::string> 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<std::string(std::string&)> task_t;
//Because packaged tasks can't be copied, binding
//shared_ptr<T>::operator() to task was a suggested solution found on
stackoverflow.
// error: invalid use of incomplete type âclass
boost::packaged_task<std::basic_string<char>(std::basic_string<char>&)>â
// error: incomplete type âtask_t {aka
boost::packaged_task<std::basic_string<char>(std::basic_string<char>&)>}â
used in nested name specifier
// boost/thread/future.hpp:1320:11: error: declaration of âclass
boost::packaged_task<std::basic_string<char>(std::basic_string<char>&)>â
{
boost::shared_ptr<task_t> example =
boost::make_shared<task_t>(boost::bind(&string_with_params, ans));
boost::future<std::string> 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<task_t> example =
boost::make_shared<task_t>(boost::bind(&string_with_params, ans));
boost::future<std::string> 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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9303> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC