Mike Weir
Mike Weir

Reputation: 3189

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.

class String {
public:
    String(String&& str) : mData(std::move(str.mData)) {
    }

private:
    std::wstring mData;
};

In Visual Studio, this works flawlessly. In Xcode, std::move() is not available.

Upvotes: 4

Views: 1655

Answers (1)

Praetorian
Praetorian

Reputation: 109119

std::move simply casts its argument to an rvalue reference. 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 );
}

Upvotes: 6

Related Questions