lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Reference member = shared_ptr


From: Vadim Zeitlin
Subject: Re: [lmi] Reference member = shared_ptr
Date: Sat, 6 Feb 2021 14:39:44 +0100

On Sat, 6 Feb 2021 00:03:54 +0000 Greg Chicares <gchicares@sbcglobal.net> wrote:

GC> On 2/5/21 5:01 PM, Greg Chicares wrote:
GC> > On 2/4/21 4:49 PM, Vadim Zeitlin wrote:
GC> [...]
GC> >> It is
GC> >> perfectly possible to declare unique_ptr<> with incomplete classes, you
GC> >> just need to take care to avoid using it before including the complete
GC> >> class declaration. And "using" here means both using it in your own code
GC> >> and in the compiler-generated special functions. So you could have kept 
the
GC> >> forward declarations unchanged and just would need to explicitly define
GC> >> BasicValues move ctor and assignment operator and dtor as "= default" in
GC> >> basicvalues.cpp file, where the full declarations of everything are
GC> >> available.
GC> > 
GC> > That sounds like it would be easy enough.
GC> 
GC> Done: new branch odd/unique_vs_shared2 . Would you recommend
GC> merging that into master?

 Yes, I think it should be merged. It's not a huge gain, of course, but it
is an improvement from the code clarity point of view IMNSHO.

 BTW, the only tiny comment I had when reading these commits was about
make_unique(): it also has another minor advantage, which is to avoid using
"raw" new, which is nice too.

GC> BTW, I defined the BasicValues dtor outside of the header, but
GC> it seems I didn't need to touch the move ctor or operator=().
GC> Perhaps those aren't used--I don't know.

 I'm sorry, I don't know what I was thinking, but move ctor and move
assignment operator don't require full declarations of the class being held
(they just move/exchange pointers), so I was completely wrong when I had
written that they had to be defined out of line, sorry for misleading you.

 And thanks for improving this!
VZ

Attachment: pgpeQsR2sCVwY.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]