Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The C++ implementation of swap given is wrong.

SomeType temp = arg1;

This would do a deep copy of the object pointed to by the ref arg1. What is intended is probably

SomeType& temp = arg1;



No, the article was right.

You can't do a generic swap without 3 deep copies.

If you change temp to be a reference, then once you do "arg1 = arg2", you just lost any way to get arg1's value back.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: