Is there a reference_wrapper<> for rvalue references?

前端 未结 4 1763
不思量自难忘°
不思量自难忘° 2020-11-30 10:43

I wonder how the following can be done

void f(string &&s) { 
  std::string i(move(s)); 
  /* other stuff */ 
} 

int main() { 
  std::string s; 
  bi         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 10:54

    You can use a mutable lambda object.

    auto func = [=]() mutable {
        f(std::move(s));
    };
    

提交回复
热议问题