C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] = default { body... } on constructors and operator=
From: Kilian Henneberger (kilis-mail_at_[hidden])
Date: 2021-02-24 10:07:23


Hi Bengt,

I suggest you wrap the m_fileHandle into a custom type which defines all
the SMFs and ensures that each one does the right thing. And then you
use that custom type as a member of RasterIO. You can just "=default;"
the move-constructor of RasterIO and are done.

Regards,
Kilian

Am 24.02.2021 um 16:43 schrieb Bengt Gustafsson via Std-Proposals:
>
> It seems rather common that move constructors and move assignment
> operators need to first move all members and then just set one member
> in the source to indicate that it has been moved from. Couldn't we
> allow a body after = default to handle this situation. Here is today's
> example:
>
>
> |RasterIO::RasterIO(RasterIO&& src) :
> m_fileName(std::move(src.m_fileName)), m_fileHandle(src.m_fileHandle),
> m_headerSize(src.m_headerSize),
>     m_footerSize(src.m_footerSize), m_type(src.m_type),
> m_width(src.m_width), m_height(src.m_height), m_depth(src.m_depth),
>     m_frames(src.m_frames), m_fileRowStride(src.m_fileRowStride),
>     m_isRaw(src.m_isRaw), m_description(std::move(src.m_description))
> {
>     src.m_fileHandle = -1;
> }|
>
> |
> |
>
> |Which could be reduced to:|
>
>
> |||RasterIO::|RasterIO(RasterIO&& src) = default {
>     src.m_fileHandle = -1;
> }||
>
> ||The current situation is both boring and reinstates the situation
> that = default was intended to remove, i.e. the verbosity and error
> proneness.||
>
> ||For constructors it would be possible to also allow : <initializers>
> between default and { which would allow special handling of a subset
> of the members, but I think this would rather rarely be useful.||
>
> ||
> ||
>
> ||What do you think?||
>
> ||Bengt||
>



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups