[Interest] qSwap or std::swap?

John Weeks john at wavemetrics.com
Mon Oct 26 16:48:55 CET 2015


> Both are correct, since one is implemented in terms of the other. That means 
> they MUST expand to exactly the same assembly (and they do, I've just tested).
> 
> If you're seeing something different, the problem is probably your code. And 
> that's why Marc is recommending qSwap: because people don't know how to use 
> std::swap. There's a big gotcha: you MUST NOT write the "std::" part of 
> std::swap.

At the risk of making a fool of myself, what is the difference? I thought I had learned that namespaces were just a scoping mechanism for names to avoid name collisions. Why does this make such a difference in the generated code?

I'm old enough now that the risk of making a fool of myself is a small price to pay in order to learn something.

-John Weeks




More information about the Interest mailing list