Boost logo

Boost :

From: Paul Moore (gustav_at_[hidden])
Date: 2001-01-22 16:29:02


On 22 Jan 2001, at 19:10, Stephen Silver wrote:

> Did you look at the generated code, or are you just guessing?
> If std::swap() is inlined, as is likely, then any reasonable compiler
> would optimise away the unnecessary assignments for built-in types.
> GCC 2.95.2 generates exactly the same code for the above two forms
> of the loop when IntType is long int.

No I didn't. While it's a good point (and I'll do so) there's still the
question for the "general" compiler. Your description, that a good
compiler should optimise away the unnecessary assignments,
makes sense and tends to imply that using std::swap() is a good
idea. But I guess I'd still appreciate confirmations.

If gcc does the optimisation, that covers a reasonably large set of
users...

[Off to check...]
Identical code with /O2. Without optimisation, the std::swap call is
a function call - not even inlined...

I also checked gcc (mingw) and got the same results.

Borland C (the free version) inlines std::swap with or without -O2,
but doesn't optimise the swap away. Oh, well...

> I think using std::swap() is a good idea.

Thanks to your discussion above, and my experiments, I now
agree...

Paul.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk