Talk:cpp/language/rule of three

I think the copy assignment operator has an unnecessary temporary in it. You can elide  if you  first.


 * This would break exception safety. In your example, if throws,  becomes a dangling pointer. MiiNiPaa (talk) 02:30, 29 August 2016 (PDT)

Reference link broken
The first reference link no longer works. Changing it to another one on same topic by the same author https://isocpp.org/blog/2012/11/rule-of-zero

--User8712 (talk) 04:56, 5 February 2021 (PST)

Bad alternative advice
This "alternative" advice is just wrong since it would effectively make assignment always a copy operation. Any objection to deleting it?

[A]ny class for which move semantics are desirable has to declare all five special member functions: // alternatively, replace both assignment operators with // rule_of_five& operator=(rule_of_five other) noexcept // { //      std::swap(cstring, other.cstring); //     return *this; // }


 * Not sure what you mean, this example shows that no copy is made --Ybab321 (talk) 16:47, 27 December 2021 (PST)

Smart pointer based rule of five?
240E:3B1:348B:45F0:2CB9:A5EC:5A98:82F7 23:48, 2 August 2022 (PDT) Smart pointer based rule of five?

Is it possible to make smart pointer version of rule of five? Will this make C++ similar to Rust? I see there is unique_ptr version of List on cppreference, see ref.

class rule_of_five { std::unique_ptr cstring; // char* cstring; ...

ref: https://en.cppreference.com/w/cpp/memory/unique_ptr

// unique_ptr-based linked list demo struct List

240E:3B1:348B:45F0:2CB9:A5EC:5A98:82F7 00:15, 3 August 2022 (PDT) I think it again. The idea is wrong in rule of five in C++. Smart pointer means share ownership or exclusive ownership. Two separate strings, s1, s2, they are not related and do not share ownership.