c++ - Use const_cast to implement the move constructor -


I have read the page about the driver.

  Namespace Details {/ p> 

Template & lt; Class T & gt; Structure proxy {T * resource_; }; } // Description Template & lt; Class T & gt; Classroomable resources {Private: T * resource_; Public: Clear MovableResource (T * r = 0): resource_ (r) {} ~ Runable Resources () Throw () {remove resource_; } // assuming that std ::: auto_ptr such behavior MovableResource (MovableResource & amp; amp; M) throw () / / "Knvensr Move" (Note Non-Const parameter): resource_ (m.resource_) {m. Resource_ = 0; // Note that the parameter is transferred to the resource *. } MovableResource (extension :: proxy & lt; T & gt; p) throw () / / proxy move maker: resource_ (p.resource_) {// Simply copying the resource indicator is enough to make it sound like a conductor builder There is no requirement. } Runable resources & amp; Operator = (Running Resources & amp; amp;; M) Throw () // Move-Assignment Operator (Note Non-Cost Parameters) {// Copy and Swap Idioms Original Release Source must be Destructive Runable (temporary) M); // Resources will be moved here Temp.swap (* this); Return * This; } Runable resources & amp; Operator = (Expansion :: Proxy & lt; T & gt; p) Throw () {// Copy and Swap Idioms The original source must be released in Nashik for running resources (P); Temp.swap (* this); Return * This; } Zero swap (running resources); () () (); (Std :: swap (this-> resource_, m.resource_);} Operator Details :: Proxy & gt; (& gt; Throw) / / An Assistant Conversion Function. Note that this non- Description: Proxy & lt; T & gt; P; p.resource_ = this- & gt; resource_; it-> resource_ = 0; // moved to temporary temporary proxy object. Return p;}};

To add a constructor to the reference and use const_cast , change the variable to apply such trick words To.

  walkable Resources (Const about Arsesr & M) {running Rensr & amp; AfterM = const_cast & lt; walkable Resource & amp; & gt; (m); afterM.swap (* This);}  

Does this present an uncredited behavior?

conduction by a copy manufacturer is asking for trouble just under the interface of the hood use const_cast to apply Semantic you're making a fool to believe customers own interface Consider that your constructor m Anmodifaid will leave, when it will turn off to prevent its value following code:

  Const walkable resource ago (/ * some Resources 'A' * /); Runable resources second (first); // 'first', it is believed that 'const' is now probably a different value!  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -