How can I make a forwarding-reference parameter bind only to rvalue references?

You can restrict T to not be an lvalue reference, and thus prevent lvalues from binding to it:

#include <type_traits>

struct OwnershipReceiver
  template <typename T,
            class = typename std::enable_if
  void receive_ownership(T&& t)
     // taking file descriptor of t, and clear t

It might also be a good idea to add some sort of restriction to T such that it only accepts file descriptor wrappers.

Leave a Comment