c++ - Releasing memory with std::move()? -


says have class standard container:

class library{     std::vector<book> books; public:     void putonfire(){         books.clear();     } }; 

the usual way clear container "clear", code not "stl compliant" many containers (by third parties) may not have "clear" method. however, if have move semantics use std::move right?

void putonfire(){     auto p = std::move(books); //books cleared when p out of scope } 

this write generic possible code works not stl container "clear" method.

std::move leaves moved-from object in valid unspecified state. in particular might stay way before, while might work implementation of stl, not work third-party containers. (and might break @ point in future when implementation of stl changes due update)


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -