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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -