0
点赞
收藏
分享

微信扫一扫

std::move

zhaoxj0217 2023-02-09 阅读 168


他滴实现

template<typename T>
typename std::remove_reference<T>::type&&
move(T&&t)
{
static_cast<typename std::remove_reference<T>::type&&>(t);
}

然后这个是remove_reference<T>

template <class  T>struct remove_reference{ typedef T type}; 
template <class T>struct remove_reference<T&>{ typedef T type};
template <class T>struct remove_reference<T&&>{ typedef T type};

这个是引用折叠

X&+&=X&;
X&+&&=&
X&&+&=&;
X&&+&&=&&

std::move(something)就是把里面的东西可以拿给你用。

例如thread  t1;  线程不可拷贝

thread t2=std::move(t1);可以

然后t1就不能用了

举报

相关推荐

0 条评论