[fpc-devel] Move operator
Jonas Maebe
jonas at freepascal.org
Sun Jul 14 14:55:37 CEST 2019
On 13/07/2019 15:13, Ryan Joseph wrote:
>
>
>> On Jul 13, 2019, at 8:21 AM, Jonas Maebe <jonas at freepascal.org> wrote:
>>
>> In which scenarios do you need such a custom "move" operator, rather
>> than simply allowing the compiler to just copy the data from one place
>> to the other without calling a destructor on the old instance?
>
> Not sure off the top of my head what would happen if the user simply wasn’t informed about the operation but it makes me nervous. :) It may be the case though that inside the move operator the most common thing is just to call System.Move anyways. Also if the operator isn’t there then there’s no way to know without a modeswitch or some other syntax that the user wants to calls system.move instead of the Copy operator.
The question then still remains: why would a user want to call a copy
operator when the data is just moved from a temp to another place?
Having an explicit copy operator when there is no use case for it only
requires programmers to write extra code that can contain bugs.
Jonas
More information about the fpc-devel
mailing list