lmi
[Top][All Lists]
Advanced

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

Re: [lmi] depr.impldec


From: Vadim Zeitlin
Subject: Re: [lmi] depr.impldec
Date: Thu, 28 Jul 2022 15:32:01 +0200

On Thu, 28 Jul 2022 09:53:07 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> On 7/28/22 00:29, Vadim Zeitlin wrote:
GC> > On Wed, 27 Jul 2022 19:55:32 +0000 Greg Chicares 
<gchicares@sbcglobal.net> wrote:
GC> > 
GC> > GC> On 7/13/22 20:51, Greg Chicares wrote:
GC> > GC> [...]
GC> > GC> > I weakly favor the Rule of Zero, while you more strongly favor
GC> > GC> > the Rule of Five, so let's start with a universal Rule of Five
GC> > GC> 
GC> > GC> I've changed my opinion.
GC> [...]
GC> >  One benefit that I hadn't mentioned yet, I think, is that if you ever
GC> > define a special member in your class, e.g. decide to do something in the
GC> > default ctor, it would silently inhibit moving. This should, arguably,
GC> > happen only rarely, but I guarantee that if it does happen, it will remain
GC> > unnoticed for a long time.
GC> 
GC> Unless we guarantee that it cannot happen, e.g., with "concept" assertions.

 True, but this would require using concepts in all places where the class
is used rather than defining the special member functions in a single
place, so it's not clear if it provides a gain from the brevity point of
view. It still might be a better idea for other reasons though, e.g. it's
arguably more important to know that the object passed to some function can
be efficiently moved rather than knowing that objects of some class can be
moved.

GC> >  Also, there are many important exceptions, e.g. you still have to write
GC> > all 5 special members for any polymorphic base classes
GC> 
GC> But we can write them all once...
GC> 
GC>   #include "crtp_base.hpp"
GC> 
GC> ...and only once:
GC> 
GC>   class A : private lmi::polymorphic_base<A> {};
GC>   static_assert( std::is_polymorphic_v           <A>);
GC>   static_assert( std::is_default_constructible_v <A>);
GC>   static_assert( std::is_destructible_v          <A>);
GC>   static_assert( std::is_copy_constructible_v    <A>);
GC>   static_assert( std::is_move_constructible_v    <A>);
GC>   static_assert( std::is_copy_assignable_v       <A>);
GC>   static_assert( std::is_move_assignable_v       <A>);
GC> 
GC> (and those assertions can be combined into one "concept").

 Just to be sure, did you really mean write all these asserts positively
like this or was it a typo? Because I'd expect polymorphic types _not_ to
be copyable nor movable.

 Regards,
VZ

Attachment: pgpVLUznH0zRe.pgp
Description: PGP signature


reply via email to

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