How to make template rvalue reference parameter ONLY bind to rvalue reference?

前端 未结 5 2051
心在旅途
心在旅途 2020-12-01 08:59

I\'m writing a network library and use move semantics heavily to handle ownership for file descriptors. One of my class wishes to receive file descriptor wrappers of other k

5条回答
  •  抹茶落季
    2020-12-01 09:33

    I learnt something that seems to confuse people quite often: using SFINAE is OK, but I can't use:

    std::is_rvalue_reference::value
    

    The only way it works as I want is

    !std::is_lvalue_reference::value
    

    The reason is: I need my function to receive an rvalue, not an rvalue reference. A function conditionally enabled with std::is_rvalue_reference::value will not receive an rvalue, but rather receives an rvalue reference.

提交回复
热议问题