[RFA] Algorithms vs operator* and operator==

chris jefferson caj@cs.york.ac.uk
Sat Nov 6 21:41:00 GMT 2004


Paolo Carlini wrote:

> Paolo Carlini wrote:
>
>> Can you spot anything wrong with this kind of change? If we agree that
>> it's good, there are quite a few places to tweak, both in stl_algo and
>> in stl_algobase (besides locale_facets ;)
>
>
> *But*, now I remember std::fill and std::fill_n: in order to avoid 
> expensive
> copies when _ValueType is "big", we should probably use temporary vars
> (like __value) *only* when __is_scalar<_ValueType>::_M_type is true...
>
Connected to this, I've been investigating a number of the algorithms 
where it can be much more efficent to implement them purely in terms of 
swap rather than assignments (reverse, sort, and others) for those 
classes where a swap is MUCH cheaper than an assignment (lists and 
vectors come to mind). However a swap is twice as expensive as an 
assignment for scalar classes, and could in theory be 3 times as 
expensive for a big class which didn't implement a swap (although I'm 
tempted to ignore these).

Therefore, similarily I have 3 options..

1) Make the int, float, etc. case efficent
2) Make the vector, list, etc case efficent
3) Use somethiing like _is_scalar (and perhaps others.. is_pod comes to 
mind)  to try to decide when to make the choice

Any opinions? :)

Chris



More information about the Libstdc++ mailing list