From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-12-05 03:48:19
David Abrahams <dave <at> boost-consulting.com> writes:
> on Mon Dec 03 2007, Anthony Williams <anthony_w.geo-AT-yahoo.com> wrote:
> > David Abrahams <dave <at> boost-consulting.com> writes:
> >> on Mon Dec 03 2007, Anthony Williams <anthony_w.geo-AT-yahoo.com> wrote:
> >>> However, I did post a message asking for a fast-track review of it so
> >>> that it
> >>> could become a documented part of boost. The only response I got was
> >>> "there's
> >>> another implementation in the sandbox".
> >> And that implementation is fatally flawed, I'm ashamed to say. We
> >> should be using http://opensource.adobe.com/group__move__related.html
> > How does that help with a movable-but-not-copyable type (such as
> > boost::thread)?
> I'm not sure, frankly; the author of that library believes all types
> are intrinsically both movable and copiable. Maybe for that purpose
> we need something else.
Can I (again) propose the simple scheme I'm using for boost::thread?
In boost/thread/detail/move.hpp we (now) have
boost::detail::thread_move_t<T> as the transfer type
and boost::detail::thread_move(T&) as the move-from-lvalue helper
boost::thread then looks like this (move-related parts only)
thread(thread&); // no copy. Note no const
thread& operator=(thread&); // no assign. Note no const
thread(detail::thread_move_t<thread>); // move constructor
thread& operator=(detail::thread_move_t<thread>); // move assignment
operator detail::thread_move_t<thread>(); // allow conversion to the
detail::thread_move_t<thread> move(); // make it explicit
If you try and construct a thread object from an rvalue then it won't bind to
the (private) copy constructor, as it can't bind to a non-const reference.
However, a single user-defined conversion (to detail::thread_move_t<thread>)
allows it to bind to the move constructor. Likewise for assignment.
It works for gcc and MSVC, but not for Borland. When the test results come
through for the new test_thread_move test, we'll know which other compilers it
works on, too.
-- Anthony Williams Just Software Solutions Ltd - 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