
Howard Hinnant wrote:
On Jan 2, 2009, at 6:45 PM, Ion Gaztañaga wrote:
I've seen that move emulation is done using a conversion operator (I think Boost.Thread uses the same technique), is that mechanism the best way to achieve this?
It is my current best effort. :-\ It does not have the move-from-const bug that my previous effort had. And it does not require clients to be aware of the "rv" or "moved-from" type (which is a characteristic I really like). In this emulation I've made that type private to emphasize the encapsulation of it from clients wanting to move unique_ptr's.
Ok. For some vector and deque code I've used the is_movable<> trait to select move_iterator or just raw pointers for internal copies. Maybe this is still necessary with your conversion operator code. Although a smart move_iterator could do the job, using raw pointers in those cases automatically takes advantage of STL uninitialized_copy/copy functions that automatically use memcpy.
Agreed. The thing I like about my current effort is that clients see either lvalue or rvalue unique_ptr's (or whatever class you're trying to move-enable) and nothing else. No moved-from wrappers. Downsides include the fact that move(unique_ptr) is a friend of unique_ptr - a tight coupling that I would rather not have there. In C++0X, move is a completely generic std-function, a characteristic not achieved by this emulation.
Well, not a big problem if the emulation works! Regards, Ion