[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Rule of five exemplar [Was: depr.impldec]
From: |
Greg Chicares |
Subject: |
[lmi] Rule of five exemplar [Was: depr.impldec] |
Date: |
Thu, 14 Jul 2022 00:20:13 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 |
On 7/13/22 21:29, Vadim Zeitlin wrote:
> On Wed, 13 Jul 2022 20:51:24 +0000 Greg Chicares <gchicares@sbcglobal.net>
> wrote:
>
> GC> - add a very brief comment on any changed line
>
> I'm not sure that even this is needed -- if you delete the copy ctor, it
> seems to say pretty clearly that you don't want the class to be copyable
> and what else could the comment say?
> GC> + // Rule of six: special member functions.
> GC> + ifstream() = default;
> GC> + ifstream(ifstream const&) = delete; // not yet needed
> GC> +// ifstream(ifstream&&) = default; // not yet needed
> GC> + ifstream& operator=(ifstream const&) = delete; // std: only move=
> GC> +// ifstream& operator=(ifstream&&) = default; // not yet needed
There are two possible reasons for not using "= default":
- I guess a defaulted member would work, but I don't want to spend time
thinking about it, and I don't need it right now anyway, so I'll just
inhibit it and not worry.
- I know that a defaulted member cannot work, and I know the reason why,
so let me document that before I forget it. Or, similarly, I tried
defaulting it, and clang warned that it would be defined as deleted,
so let me write '-Wdefaulted-function-deleted' for posterity.
Isn't it worth writing a very few words to give the reason why, or to
say there's no particular reason?
Alternatively, if there's no particular reason, we might say nothing
(there being nothing in particular to say); but if there's a reason,
then say it. In the example above, that approach would have only one
comment, the one on the copy assignment operator; I spent time trying
to figure out why you had deleted it, and that led me to the tentative
conclusion that it's because std::ifstream has only move assignment.
- [lmi] depr.impldec, Greg Chicares, 2022/07/09
- Re: [lmi] depr.impldec, Greg Chicares, 2022/07/13
- Re: [lmi] depr.impldec, Greg Chicares, 2022/07/27
- Re: [lmi] depr.impldec, Vadim Zeitlin, 2022/07/27
- Re: [lmi] depr.impldec, Greg Chicares, 2022/07/28
- Re: [lmi] depr.impldec, Vadim Zeitlin, 2022/07/28
- Re: [lmi] depr.impldec, Greg Chicares, 2022/07/28
- Re: [lmi] depr.impldec, Vadim Zeitlin, 2022/07/28
Re: [lmi] depr.impldec, Greg Chicares, 2022/07/13