How can I define a function which bind only xvalue OR prvalue but not both

Viewed 218

Is there a way to define a function which handle only xvalue or prvalue (or is here a exclusive or) ?

For instance suppose I have a method f(foo&& f), how can I declare f to bind xvalue type and reject prvalue type and vice versa ?

struct Foo{};
void xvalue(/*what put here ?*/){}
void prvalue(/*what put here ?*/){}

void main()
{
  Foo foo;

  prvalue(Foo());//compile
  prvalue(std::move(foo)));//fail at compilation

  xvalue(std::move(foo)); //compile
  xvalue(Foo());//fail at compilation
}

Maybe by using std::enable_if and the fact that decltype(e) is a rvalue reference type for xvalues and non-reference type for prvalue ?

1 Answers
Related