Mik*_*eir 4 c++ std rvalue-reference move-semantics c++11
我正在使用具有C ++ 0x规范的C ++编译器,并希望使我的move构造器成为环绕std :: wstring的String类。
class String {
public:
String(String&& str) : mData(std::move(str.mData)) {
}
private:
std::wstring mData;
};
Run Code Online (Sandbox Code Playgroud)
在Visual Studio中,这完美无缺。在Xcode std::move()中不可用。
std::move只需将其参数转换为右值引用即可。您可以编写自己的版本:
template<class T>
typename std::remove_reference<T>::type&&
move( T&& arg ) noexcept
{
return static_cast<typename std::remove_reference<T>::type&&>( arg );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1093 次 |
| 最近记录: |