I don't understand the reason why std::move() had to be created. Couldn't everything just be static_cast<T&&>() instead? The only reason that I find why std::move() might have been created is just to make code easier to read. So, instead of seeing static_cast, programmers could see std::move() and understand what it is doing. Other than that, I see no purpose. Can someone help me understand why they created std::move()?.
Yes, it's mostly about readability.
In addition to clearly expressing the intent, std::move doesn't require you to manually write the type.
A quick googling on the proposal n1377
The static_cast<A&&> syntax is admittedly ugly. This is not necessarily a bad thing as you want to clearly call out when you are doing something as dangerous (and useful!) as moving from an lvalue. But the cast can become so ugly as to be unreadable when the type A is a long complicated identifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With