Jon Stewart on 19 May 2003 17:47:01 -0000


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

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


> 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.


While I agree with Arlo that combinatorial problems should be solved in
like manner, this is not a combinatorial problem per se. It's really a
special case of a stupid compiler trick, and one that is, IMHO, utterly
braindead. What Chris really wants to do is have the function take a
reference and then have it return a reference, possibly the same one he
passed in: the semantics are clear.

Chris, am I correct in presuming that the optimization occurs for small 
types only, i.e. T where sizeof(T) < X? 

If so, then what you can do is take the call traits solution (using both
ParamT<> and RetT<>) and define policies for it deciding whether to return
references based upon the expression sizeof(T) < X. This is "dangerous",
in that X is an arbitrary and capricious number chosen by the damn
compiler, but, hey, at least you've now got it in as a simple #define
value**, which you can #ifdef based on the compiler.



Jon


** Gotcha'! :-)
-- 
Jon Stewart
stew1@xxxxxxxxxxx
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp