From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15125 invoked by alias); 1 Nov 2011 11:00:36 -0000 Received: (qmail 15114 invoked by uid 22791); 1 Nov 2011 11:00:35 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 01 Nov 2011 11:00:13 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RLC4d-0004Bh-LI for gcc-help@gcc.gnu.org; Tue, 01 Nov 2011 12:00:07 +0100 Received: from cm-84.208.113.69.getinternet.no ([84.208.113.69]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Nov 2011 12:00:07 +0100 Received: from larsbj by cm-84.208.113.69.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Nov 2011 12:00:07 +0100 To: gcc-help@gcc.gnu.org From: larsbj@gullik.org (Lars Gullik =?iso-8859-1?Q?Bj=F8nnes?=) Subject: std::packaged_task trunk problem Date: Tue, 01 Nov 2011 11:00:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg00000.txt.bz2 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 #include #include template std::future::type> spawn_task(F f) { typedef typename std::result_of::type result_type; std::packaged_task task(std::move(f)); std::future 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 >’: /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 >’ /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()>’ /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; _Args = {}]’ packaged_task_example.cpp:12:5: required from ‘std::future::type> spawn_task(F) [with F = int (*)(); typename std::result_of::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; _Tail = {}; std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, std::packaged_task >]’ declared to take const reference, but implicit declaration would take non-const Thanks, -- Lgb