简体   繁体   English

我可以使用什么代替std :: move()?

[英]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.

相关问题 我可以/通常使用std :: forward而不是std :: move吗? - Can I typically/always use std::forward instead of std::move? 我应该使用什么而不是std :: ostrstream? - What should I use instead of std::ostrstream? 在较旧的C ++标准中,我可以用什么代替std :: string :: pop_back? - What can I use instead of std::string::pop_back in older C++ standard? 在MS Visual Studio 2013中,我可以使用什么代替std :: aligned_alloc? - What can I use instead of std::aligned_alloc in MS Visual Studio 2013? 是std :: vector需要使用move而不是copy吗? - are std::vector required to use move instead of copy? 我可以在函数的结果上使用std :: move来构造一个新对象吗? - Can I use std::move on the result of function to construct a new object? 我可以在 std::move 之后重复使用像 std::vector 这样的复杂 class 吗? - Can I re-use a complex class like std::vector after std::move? 我可以使用std :: move与不提供移动构造函数的类吗? - can I use std::move with class that doesn't provide a move constructor? 我可以用什么而不是strstream :: freeze? - What I can use instead of strstream::freeze? 我可以使用什么来代替箭头运算符`-&gt;`? - What can I use instead of the arrow operator, `->`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM