First of all, thank you very much.
MyClass<int*> obj = new int{50};
is the same as
MyClass<int*> obj = MyClass<int*>(new int{50}); |
THIS actually tricked me.
The Universal Constructor uses an Universal Reference (U&&) which can basically take everything.
I thought that, in the
first call of the Universal Constructor, the pointer returned by
new was passed!
Why doesn't the Universal Constructor get called with the
temporary pointer becoming this way
|
constexpr MyClass(int*&& u) : ptr_(forward<int*>(u))
|
Instead, a temporary MyClass object is created before calling the Universal Constructor for the first time, so that it becomes:
|
constexpr MyClass(MyClass<int*>&& u) : ptr_(forward<MyClass<int*>>(u))
|
I mean... why? By passing the pointer returned by
new int{50} we could've been avoided the conversion...
P.S: Why if I enable copy elision, I only get
Which steps are skipped with copy elision in this case?