« first day (2134 days earlier)      last day (722 days later) » 

6:52 AM
As per the (document)[], the third declaration is unique_ptr& operator=( std::nullptr_t ) noexcept;. What's the difference between unique_ptr& operator=( std::nullptr_t ) noexcept; and unique_ptr operator=( std::nullptr_t ) noexcept;? Must the assignment operator returns a reference other than an object?
 
7:32 AM
@John the assignment operator returning a reference is a convention. Because you can always use assignments as part of a larger expression like.

(a=b).get();
 
7:54 AM
@PeterT If the said copy assignment operator returns object other than reference, the aforementioned expression seems still work well. Am I right?
 
8:26 AM
It works, it's just not what most people would expect
Not that I think it's something you should write but maybe this demonstrates it better

a = b = c ;
 
I see, than you.
 
9:30 AM
As per the [document](https://en.cppreference.com/w/cpp/memory/shared_ptr/operator_cmp), which says that:
template < class T, class U >
bool operator==( const std::shared_ptr<T>& lhs,
const std::shared_ptr<U>& rhs ) noexcept;

It indicates `lhs` and `rhs` could be different types. What surprises me is that the [code snippet](https://godbolt.org/z/rTdz8ehec) does not compile. I fully understand what the compiler complains. What confuses me is the said document says the `lhs` and `rhs` could be different types.
The link should be godbolt.org/z/r5h8bEEWf
 
 
3 hours later…
nwp
12:32 PM
@John If you have a Base *b and a Derived *d then b == d compiles, assuming Derived derives from Base. Similarly std::shared_ptr<Base> and std::shared_ptr<Derived> can be compared. So they can be different types, but not just any different types, they still have to be comparable.
 
 
3 hours later…
3:08 PM
I see, thank you.
Why std::make_shared does not work anymore when the class Widget inherits class enable_shared_from_this, whereas it works well if you remove the inheritance.
 
nwp
3:30 PM
There is some compiler weirdness going on there. The version that is supposed to work well doesn't compile with clang. It's probably not supposed to compile.
I think the example can be reduced by removing the std::shared_ptr stuff and just do Widget w1; vs Widget w2(std::vector{1,2,3}, 9);, though different compilers seem to have different opinions about that too.
gcc rejects Widget w2(std::vector{1,2,3}, 9); while accepting Widget w2(std::vector<int>{1,2,3}, 9); which is just weird. clang rejects both.
I don't know who is right here.
 

« first day (2134 days earlier)      last day (722 days later) »