<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 23, 2015 at 9:16 PM, Alex Rousskov <span dir="ltr"><<a href="mailto:rousskov@measurement-factory.com" target="_blank">rousskov@measurement-factory.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On 08/19/2015 11:11 PM, Amos Jeffries wrote:<br>
<br>
> * when adding a new constructor ensure the big-5 operators (ctor, dtor,<br>
> assign, emplace, emplace-assign) are all present. Even if they use "=<br>
> default"<br>
<br>
</span>IMO, the above rule is wrong because it forces developers to add<br>
absolutely unnecessary code in many cases (unnecessary from any points<br>
of view, even code readability and documentation).<br>
<br>
<br>
A better set of rules would say something like this:<br>
<br>
Big3 methods: copy constructor, destructor, and assignment operator.<br>
Move methods: move constructor and move assignment operator.<br>
<br>
0. If the class works well without any of the Big3 methods, do not<br>
define any of the Big3 methods.<br>
<br>
1. If you have to define one of Big3, declare all of Big3.<br>
<br>
2. If your class has a non-default destructor implementation, you may<br>
decide to define one of the Move methods. If you define one Move method,<br>
declare the other Move method as well.<br>
<br>
3. Whenever you declare a method, use a "= default" declaration when the<br>
default method implementation matches your needs and use a "= delete"<br>
declaration when using the declared method is prohibited.<br></blockquote><div><br></div><div>Sounds excellent to me.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
[ I also like the "Rule of 0" that states that "if you specify any of<br>
the default members, then your class must deal exclusively with a single<br>
resource", but we probably have too many violations of this rule and too<br>
many raw pointers floating around to enforce it. ]<br></blockquote><div><br></div><div>We can try adding that as an encouragement; won't fix the past but it may help for the future.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
AFAICT, StoreMeta in the last patch does not satisfy rule #3. To satisfy<br>
that rule, StoreMeta should:<br>
<br>
* use "= default" for the virtual destructor<br>
<br>
* use either "= default" or "= delete" for the copy constructor and the<br>
assignment operator.<br>
<span class=""><br>
<br>
> Omitting emplace and implementing the others as protected for<br>
> completeness' sake.<br>
<br>
</span>Why protected?<br>
<br>
* Making default constructor protected is the same as keeping it public<br>
because the class is abstract (nobody can create a StoreMeta object).<br>
<br>
* If you want to prohibit copying, use "= delete" for copy constructor<br>
and assignment operator. Given the class use of raw pointers, deleting<br>
sounds like a good idea, but I did not study this class usage in detail.<br>
In general, prohibiting dangerous operations is better than allowing<br>
them so if "= delete" works well, we should use it.<br></blockquote><div><br></div><div>With private (on clang)<br><br>StoreMeta.cc:100:22: error: call to implicitly-deleted default constructor of 'StoreMetaMD5'<br>        result = new StoreMetaMD5;<br>                     ^<br>../src/StoreMetaMD5.h:16:22: note: default constructor of 'StoreMetaMD5' is implicitly deleted because base class 'StoreMeta' has an inaccessible default constructor<br>class StoreMetaMD5 : public StoreMeta<br>                     ^<br><br></div><div><br></div></div><br>-- <br><div class="gmail_signature">    Francesco</div>
</div></div>