std::move() is just casting?

前端 未结 2 1611
执笔经年
执笔经年 2021-01-21 06:56

I have read a few (pesudo) implementions of std::move(). And all are just casting away the reference of the parameter and then returning it as a rvalue reference.

It do

2条回答
  •  生来不讨喜
    2021-01-21 07:59

    Yes, std::move is a bit of a misnomer as it doesn't actually move anything. It is used to indicate that an object may be "moved from".

    It does this by casting the object to a T&&. cppreference states the return value is static_cast::type&&>(t). (btw, that is exactly what VS2017 does)

    I don't know precisely what the standard says on the matter.

提交回复
热议问题