Boost logo

Boost :

Subject: Re: [boost] [move] interest: the pass-by-value and swap idiom, and explicit copy constructors
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2014-02-17 02:44:16


2014-02-15 14:58 GMT+01:00 Krzysztof Czainski <1czajnik_at_[hidden]>:

> 2014-02-15 14:11 GMT+01:00 Adam Wulkiewicz <adam.wulkiewicz_at_[hidden]>:
>
> Hi,
>>
>> Krzysztof Czainski wrote:
>>
>>> 2014-02-15 1:13 GMT+01:00 Adam Wulkiewicz <adam.wulkiewicz_at_[hidden]>:
>>>
>>> b) here I have a copy as well, probably because Matrix has a non-static
>>>> data member without a move assignment operator and that is is not trivially
>>>> copyable
>>>> c = boost::move(b);
>>>> after declaring "proper" move assignment in the member class (instead of
>>>> copy and swap) or using copy and swap + move ctor in Matrix everything
>>>> works as expected.
>>>>
>>>> Do you get a copy in C++11 here? I get a move() in C++11, and a copy in
>>> C++98. And that's what I expect, because C++11 auto-generates copy- and
>>> move-assignment operators, and both use the pass-by-value assignment of
>>> CopyMoveDemo correctly.
>>>
>>
>> Yes, in GCC4.7, Clang3.2, MinGW 4.7, VS2010, VS2013.
>>
>> However VS isn't good for testing the standard. For instance it doesn't
>> implicitly delete the copy ctor if move ctor is defined and therefore
>> permits copying.
>>
>> Assuming that my understanding is correct, with copy and swap the move
>>>> assignment operator can't be implicitly declared.
>>>>
>>> Why?
>>>
>>
I asked about this on comp.lang.c++.moderated:
https://groups.google.com/forum/#!topic/comp.lang.c++.moderated/6KvOCkFdcR8

In short, MinGW-4.8 seems to follow the proposed resolution to this defect:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1402

In any case, don't let this issue hide the main idea in my proposal, which
is:
- adding to Boost.move a possibility for the user to define the assignment
operator in terms of pass-by-value and swap;
- making copy constructors explicit, to be used together with `copy()` -- a
complimentary function to `move()`.

Cheers,
Kris


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