c++ - Is it safe to swap an instance of map with a temporary map? -
using std :: map; Map & lt; String, int & gt; MapStrToInt; {Map & lieutenant; String, int & gt; MapStrToInt2; MapStrToInt2 ["h1"] = 100; MapStrToInt2 ["h2"] = 200; MapStrToInt2 ["h3"] = 300; MapStrToInt2 ["h4"] = 400; MapStrToInt.insert (mapStrToInt2.begin (), mapStrToInt2.end ()); MapStrToInt.swap (mapStrToInt2); // Is this code safe? } // MapStrToInt2 has been deleted at this point. Question & gt; I have tested this code with VS2013 and the content of mapStrToInt has been replaced with mapStrToInt2 . However, I still want to make sure that the contents of a floating object are safe to swap & amp; Legal. Thanks
Both of these are safe and legal to swap the contents of two containers Time, the ownership of content changes from one to the other, therefore the temporary ownership of the old content of mapStrToInt is inherently in existence while leaving the realm, while the old content of the temporary mapStrToInt .
Comments
Post a Comment