c++ - Using std::move for a "take" method implementation -


i implement "take" method. "take" method method, steals getted object owner: owner left object in empty state. of course, involves c++11 move semantics. of following best way implement it?

class b { public:      take_a_1()     {         return std::move(m_a);     }      // can compiled looks weird me std::move      // not complain i'm passing constant object     take_a_2() const     {         return std::move(m_a);     }      a&& take_a_3()     {         return std::move(m_a);     }      // can't compiled (which fine)     //     // a&& take_a_4() const     // {     //     return std::move(m_a);     // }  private:      m_a; }; 

none of them. i'd use this:

struct b {     && get() && { return std::move(m_a); } }; 

that way can "take" rvalues of b:

b b; a = std::move(b).get(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -