mercredi 1 février 2017

How to accept both right and left references in C++?

I would like to have member function that accepts both left and right references to some class and moves it's object. Currently I have two separate functions:

void ThrSafeQueue::push(Obj&& x) {
  lock_guard(mutex_);
  queue_.push(x);
}
void ThrSafeQueue::push(Obj& x) {
  lock_guard(mutex_);
  queue_.push(std::move(x));
}

Aucun commentaire:

Enregistrer un commentaire