On implementing std::swap in terms of move assignment and move constructor

前端 未结 4 2114
刺人心
刺人心 2020-12-05 15:54

Here is a possible definition of std::swap:

template
void swap(T& a, T& b) {
  T tmp(std::move(a));
  a = std::move(b);
          


        
4条回答
  •  甜味超标
    2020-12-05 16:25

    I believe that is not a valid definition of std::swap because std::swap is defined to take lvalue references, not rvalue references (20.2.2 [utility.swap])

提交回复
热议问题