From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-05-27 18:02:07
Sohail Somani <sohail_at_[hidden]> writes:
> David Abrahams wrote:
>> I just discovered that while none of my standard containers are
>> "move-aware" in the way needed by boost::thread, I can use boost::array
>> to store threads by simply move-assigning new threads into the elements
>> it contains:
>> boost::array<boost::thread, 100> thread_q;
>> for (int i = 0; i < 100; ++i)
>> thread_q[i] = boost::thread( some_function );
>> it ain't perfect, but given that the number of cores on any real machine
>> is limited these days, you can do a lot with a fixed-size array of
>> thread. Pretty cool; it sure beats using shared_ptr.
> Why doesn't it require std::move or boost::move? I thought this was
> required to move anything. Looks like there is some sort of conversion
You only need std::move or boost::move to move an lvalue. If you've
got an rvalue (such as the temporary in Dave's example),
move-assignment "just works" in most cases.
In boost 1.35.0 this is done with a move-emulation trick involving
conversions to boost::detail::thread_move_t<>, but on trunk it uses
rvalue references if the compiler supports it.
-- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk