Move semantics for conversion operator

What is the syntax for a movable conversion operator?

I have a wrapper that wraps around obj that has an obj conversion statement:

 class wrap { public: operator obj() { ... } private: obj data_; }; 

How do I know whether to copy or move data_ ?

+6
c ++ c ++ 11 move-semantics
May 25 '12 at 17:12
source share
1 answer

The syntax for this would be something like this:

 class wrap { public: operator obj() const & { ... } //Copy from me. operator obj() && { ... } //Move from me. private: obj data_; }; 

The first version will be called when the second version cannot be called (i.e. the converted wrap instance is not temporary or std::move is not explicitly used).

Note that Visual Studio does not implement this aspect of r-value references.

+8
May 25 '12 at 17:17
source share



All Articles