Christopher Smith on 17 May 2003 04:37:01 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] Chris' stupid C++ trick of the week


On Fri, 2003-05-16 at 20:15, arlo@xxxxxxxxx wrote:
> In fact, this second approach is the one that Boost takes. Check out their
> call_traits library (http://www.boost.org/libs/utility/call_traits.htm)
> for their implementation. They are generally trying to solve a similar
> problem (allowing the function to declare that it takes a const ref,
> without worrying about whether T is instantiated with a const type). Their
> solution happens to also address the question at hand, so I thought that
> I'd bring it up.

So, after I sent the original e-mail, I thought about how boost solves
this problem. While it is more elegant than many of the solutions I have
suggested, what I don't like about it (along with some of my solutions),
is that it actually forces a copy operation to occur.

So, the compiler optimization that we're trying to make allowances for
here, is overwhelming likely to be a relatively small win. Sure,
repeated over tons of iterations it could be huge win, but for the 90%
case, it's so much not a win that compilers will not elect to use it.
I'd much rather require the programmer to be clever for the 10% case
than have to deal with *really* subtle optimization behavior like this.

This "optimization" can potentially leave programmers working with a bad
stack pointer and force them to do a copy where in the 90% case it will
be suboptimal. Unless I'm missing something this just doesn't seem like
a language feature that is at all reasonable.

BTW, does anyone know of compiler flags for various compilers which turn
off this optimization? I've always thought it annoying, and this
templating issue just magnifies it to the point of insanity.

--Chris
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp