GNU gcc 4.3 partially supports the upcoming c++0x standard: among the implemented features the rvalue reference. By means of the rvalue reference it should be possible to move a non-copyable object or return it from a function.
Are std::streams already movable by means of rvalue reference or does the current library implementation lack something?
In the current g++ svn, rvalue reference support has not yet been added to streams. I suspect adding it will not be too difficult and as ever with open source software, patches are, I'm sure, welcome!
After a quick investigation it comes out that the rvalue reference support has not been added yet to streams.
To return a non-copyable object from a function indeed it is sufficient to implement the move constructor as follows:
struct noncopyable
{
noncopyable()
{}
// move constructor
noncopyable(noncopyable &&)
{}
private:
noncopyable(const noncopyable &);
noncopyable &operator=(const noncopyable &);
};
Such constructor is supposed to transfer the ownership to the new object leaving the one being passed in a default state.
That said, it is possible to return an object from a function in this way:
noncopyable factory()
{
noncopyable abc;
return std::move(abc);
}
While std::stream does not support move constructors it seems that STL containers shipped with gcc 4.3.2 do already support it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With