[英]What can I use instead of std::move()?
I'm using a C++ compiler with the C++0x specification, and want to make my move constructor for a String class that wraps around a std::wstring. 我正在使用带有C ++ 0x规范的C ++编译器,并希望为包含std :: wstring的String类创建移动构造函数。
class String {
public:
String(String&& str) : mData(std::move(str.mData)) {
}
private:
std::wstring mData;
};
In Visual Studio, this works flawlessly. 在Visual Studio中,这完美无瑕。 In Xcode,
std::move()
is not available. 在Xcode中,
std::move()
不可用。
std::move
simply casts its argument to an rvalue reference. std::move
只是将其参数强制转换为右值引用。 You could write your own version: 你可以写自己的版本:
template<class T>
typename std::remove_reference<T>::type&&
move( T&& arg ) noexcept
{
return static_cast<typename std::remove_reference<T>::type&&>( arg );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.