Well, didn't differentiate this behavior difference before.
disable RVO:
-fno-elide-constructors
move constructor binds to R-value.
(includes x-value and pr-value,
test under -fno-elide-constructors enabled.)
cppref : move_constructor
Making move_constructor 'delete' will
prevent Type taking pr-value object to create the type instance,
even Type implemented copy constructor interface.
'=delete' is another usage paradigm
Type copy by value by pr-value will always never call
move-constructor, thus no side-affect, since it's optimized
directly through constructor, no need to do another useless
move construct.
move assign operator, OTOH, binds to pr-value, x-value. like other functions.
Initialize type instance with pr-value, will call default copy constructor; however, this is usually eliminated due to no bother just initialize the type instance with pr-value directly. Same idea behind function taking copy-by-value argument with pr-value will eliminate extra copy-constructor call.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.