I am guessing that it's because the move constructor was implicitly defined but not the copy constructor.
No, both are implicitly defined for class Something
.
Why is the copy constructor being resolved to the templated forwarding reference constructor
Because the copy constructor takes const Something&
as its parameter. That means for the copy constructor to be called, implicit conversion is needed for adding const
qualifier. But the forwarding reference constructor could be instantiated to take Something&
as its parameter, then it's an exact match and wins in the overload resolution.
So if you make something
const
, the implicitly defined copy constructor will be invoked for the 3rd case instead of the forwarding reference constructor.
LIVE
but not the move constructor?
Because for the move constructor the above issue doesn't matter. For the invocation of the 1st and 2nd case, both implicitly defined move constructor and forwarding reference constructor are exact match, then non-template move constructor wins.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…