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

前端 未结 5 2050
心在旅途
心在旅途 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:38

    For lvalue references, T is deduced to be an lvalue reference, and for rvalue references, T is deduced to be a non-reference.

    So if the function binds to a rvalue reference, what is seen at the end by the compiler for a certain type T is:

    std::is_rvalue_reference::value

    and not

    std::is_rvalue_reference::value

提交回复
热议问题