Boost logo

Boost :

Subject: [boost] [future William proposal] packaged_task do not accept boost::ref of a nullary functor
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-03 12:53:09


Hi,

packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task accept them? How can the user workaround this issue? How thread solved this issue?

Thanks in advance,
Vicente
=====================
Compiler error:

../../../../boost/futures/future.hpp: In member function `void boost::detail::task_object<R, F>::do_run() [with R = int, F = boost::reference_wrapper<non_copyable_functor>]':
test.cpp:250: instantiated from here
../../../../boost/futures/future.hpp:1206: error: no match for call to `(boost::reference_wrapper<non_copyable_functor>) ()'

=====================
Here it is the code:
struct non_copyable_functor
    : boost::noncopyable
{
    unsigned value;
    typedef unsigned result_type;
    
    non_copyable_functor():
        value(0)
    {}
    
    unsigned operator()()
    {
        value=999;
        return value;
    }
};
void do_test_creation_through_reference_wrapper()
{
    non_copyable_functor f;
    boost::packaged_task<unsigned > tsk(boost::ref(f));
    tsk(); // COMPILER ERROR HERE
    //boost::future<unsigned > act = tsk.get_future();
    //boost::thread thr(boost::move(tsk));
    //unsigned res = act.get();
    //BOOST_CHECK_EQUAL(res, 999u);
    //BOOST_CHECK_EQUAL(f.value, 999u);
}

_____________________
Vicente Juan Botet Escribá


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk