[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] depr.impldec
From: |
Greg Chicares |
Subject: |
Re: [lmi] depr.impldec |
Date: |
Wed, 27 Jul 2022 19:55:32 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 |
On 7/13/22 20:51, Greg Chicares wrote:
[...]
> I weakly favor the Rule of Zero, while you more strongly favor
> the Rule of Five, so let's start with a universal Rule of Five
I've changed my opinion.
After following that path for a while, e.g.:
6a59da54d When in doubt, prefer the Rule of Five to the Rule of Zero
4d052024d Follow the Rule of Five
702c4cddd Follow the Rule of Zero (initializing all data members in class)
7d05361b5 Follow the Rule of Zero, even expunging a virtual dtor
601db1782 Follow the Rule of Zero
I asked myself whether it seemed good to follow it all the way to the end,
adding approximately five defaulted special members to every other class
in lmi. Looking back over those changes, I found that I really dislike them:
I see only clutter and no benefit.
A different conclusion might be reached for a different codebase,
but in lmi, most classes are designed to hold only movable types (e.g.,
std::string rather than char*; std::unique_ptr<X> rather than X*).
I guess the term for this is "value semantics", as in this example:
class text
{
public:
// This type has value semantics.
text() = default;
text(text const&) = default;
text(text&&) = default;
text& operator=(text const&) = default;
text& operator=(text&&) = default;
[... snip six functions defined inline ...]
private:
std::string html_;
};
from which I won't remove the five special members, although I've
removed them from code I personally wrote. When I glance at this,
I visually fast-forward after that block, after pausing briefly
to verify that it's all just "= default" boilerplate; the absence
of an explicit destructor is invisible to me.
I've striven for "value semantics" out of aversion to the tedious
labor of writing copy special member functions, in pre-C++11 days;
as an unexpected reward, the move members are now free.
- [lmi] depr.impldec, Greg Chicares, 2022/07/09
- Re: [lmi] depr.impldec, Greg Chicares, 2022/07/13
- Re: [lmi] depr.impldec,
Greg Chicares <=
- 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