public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* std::packaged_task trunk problem
@ 2011-11-01 11:00 Lars Gullik Bjønnes
  2011-11-01 15:03 ` Jonathan Wakely
  0 siblings, 1 reply; 21+ messages in thread
From: Lars Gullik Bjønnes @ 2011-11-01 11:00 UTC (permalink / raw)
  To: gcc-help


I am trying out trunk and the std::packaged_task in C++11. I found an
example on usage at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2709.html
but are unable to make it work.

I wonder if it is the example or if it is the libstdc++ playing up.

#include <iostream>
#include <future>
#include <thread>

template<typename F>
std::future<typename std::result_of<F()>::type> spawn_task(F f)
{
    typedef typename std::result_of<F()>::type result_type;
    std::packaged_task<result_type()> task(std::move(f));
    std::future<result_type> res(task.get_future());
    std::thread(std::move(task));
    return res;
}


int get_res()
{
	return 42;
}


int main()
{
	auto f = spawn_task(get_res);
	std::cout << "Res = " << f.get() << std::endl;
}


$ /opt/gcc/gcc-trunk/bin/g++ -Wall -Wextra -O2 -std=gnu++0x packaged_task_example.cpp 
In file included from /opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/functional:56:0,
                 from /opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/future:38,
                 from packaged_task_example.cpp:2:
/opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/tuple: In instantiation of ‘struct std::_Tuple_impl<0ul, std::packaged_task<int()> >’:
/opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/tuple:398:11:   required from ‘class std::tuple<std::packaged_task<int()> >’
/opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/functional:1546:39:   required from ‘struct std::_Bind_simple<std::packaged_task<int()>()>’
/opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/thread:133:9:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = std::packaged_task<int()>; _Args = {}]’
packaged_task_example.cpp:12:5:   required from ‘std::future<typename std::result_of<F()>::type> spawn_task(F) [with F = int (*)(); typename std::result_of<F()>::type = int]’
packaged_task_example.cpp:25:29:   required from here
/opt/gcc/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/tuple:274:17: error: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 0ul; _Head = std::packaged_task<int()>; _Tail = {}; std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, std::packaged_task<int()> >]’ declared to take const reference, but implicit declaration would take non-const

Thanks,

-- 
   Lgb

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2011-11-07 22:43 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 11:00 std::packaged_task trunk problem Lars Gullik Bjønnes
2011-11-01 15:03 ` Jonathan Wakely
2011-11-01 15:08   ` Jonathan Wakely
2011-11-01 15:13     ` Lars Gullik Bjønnes
2011-11-02  0:56       ` Jonathan Wakely
2011-11-02  2:01         ` Lars Gullik Bjønnes
2011-11-02  9:06           ` Jonathan Wakely
2011-11-02 10:03             ` Jonathan Wakely
2011-11-02 11:22               ` Jonathan Wakely
2011-11-02 12:01                 ` Jonathan Wakely
2011-11-03 13:13                   ` Lars Gullik Bjønnes
2011-11-03 16:18                     ` Jonathan Wakely
2011-11-03 16:18                       ` Jonathan Wakely
2011-11-07  9:26                         ` Lars Gullik Bjønnes
2011-11-07  9:51                           ` Jonathan Wakely
2011-11-07  9:53                             ` Jonathan Wakely
2011-11-07 10:09                               ` Lars Gullik Bjønnes
2011-11-07 10:37                                 ` Jonathan Wakely
2011-11-07 10:47                                   ` Lars Gullik Bjønnes
2011-11-07 10:48                                     ` Jonathan Wakely
2011-11-07 22:43                                       ` Lars Gullik Bjønnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).