Passing a reference-to-function as a universal reference

前端 未结 1 656
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 23:26

I\'m struggling to understand what exactly happens when passing a reference-to-function to a function as a universal reference (what type is being deduced). Let\'s suppose w

1条回答
  •  被撕碎了的回忆
    2021-01-13 00:15

    A std::move is a glorified static_cast to rvalue reference type. The standard says that casting to an rvalue reference to function type still yields an lvalue. Per [expr.static.cast]/p1:

    The result of the expression static_cast(v) is the result of converting the expression v to type T. If T is an lvalue reference type or an rvalue reference to function type, the result is an lvalue;

    Concerning the value category of the std::move() function call, which returns an rvalue reference designating the result of the conversion, we can also see from [expr.call]/p10 that a function call is an lvalue if its return type is an rvalue reference to function type:

    A function call is an lvalue if the result type is an lvalue reference type or an rvalue reference to function type, an xvalue if the result type is an rvalue reference to object type, and a prvalue otherwise.

    0 讨论(0)
提交回复
热议问题