Is there a reason declval returns add_rvalue_reference instead of add_lvalue_reference

前端 未结 4 1422
无人及你
无人及你 2020-12-13 18:18

changing a type into a reference to a type, allows one to access the members of the type without creating an instance of the type. This seems to be true for bot

4条回答
  •  孤街浪徒
    2020-12-13 18:48

    You want to be able to get back aT, a T&, or const/volatile qualified versions thereof. Since may not have a copy or move constructor, you can't just return the type, i.e., a reference needs to be returned. On the other hand, adding an rvalue teference to a reference type has no effect;

     std::declval  -> T&&
     std::declval -> T&
    

    That is, adding an rvalue reference type has the effect of yielding a result which looks like an object of the passed type!

提交回复
热议问题