[C++0x] a better <future>

Jonathan Wakely jwakely.gcc@gmail.com
Mon Jun 22 07:44:00 GMT 2009


2009/6/20 Jonathan Wakely:
>
> I'll do the check in tomorrow.

This is in now.

Here's a pretty printer patch I'm working on for futures, output looks like:

Breakpoint 1, main () at promise.cc:16
16        std::packaged_task<int(int)> task(inc);
(gdb) n
17        std::shared_future<int> f1 = task.get_future();
(gdb) p task
$1 = std::packaged_task (not ready, future not retrieved)
(gdb) n
18        task(2);
(gdb) p f1
$2 = std::shared_future (not ready, shares state with 1 other object)
(gdb) p task
$3 = std::packaged_task (not ready, shares state with 1 other object)
(gdb) n
19        int i = f1.get();
(gdb) p task
$4 = std::packaged_task (has value, shares state with 1 other object)
(gdb) p f1
$5 = std::shared_future (has value, shares state with 1 other object)

I want to improve the output for packaged_task, currently it only
prints the promise object, not the stored function object, which looks
like this:

$3 = {
  _M_task = {<std::_Maybe_unary_or_binary_function<int, int>> =
{<std::unary_function<int, int>> = {<No data fields>}, <No data
fields>}, <std::_Function_base> = {static _M_max_size = 16, static
_M_max_align = 8, _M_functor = {_M_unused = {_M_object = 0x4019ed,
_M_const_object = 0x4019ed,
          _M_function_pointer = 0x4019ed <inc(int)>, _M_member_pointer
= &virtual table offset 4200940, this adjustment 64971124},
        _M_pod_data =
"�\031@\000\000\000\000\000ta�\003\000\000\000"},
      _M_manager = 0x406137 <std::_Function_base::_Base_manager<int
(*)(int)>::_M_manager(std::_Any_data&, std::_Any_data const&,
std::_Manager_operation)>}, _M_invoker = 0x406110
<std::_Function_handler<int ()(int), int
(*)(int)>::_M_invoke(std::_Any_data const&, int)>},
  _M_promise = std::promise (has value, shares state with 1 other object)}

which isn't very pretty :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: future-printer.patch
Type: text/x-patch
Size: 3715 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20090622/f902ebe6/attachment.bin>


More information about the Libstdc++ mailing list