This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: vector<T>::iterator


On Thu, Jul 31, 2003 at 05:55:49PM +0200, Bo Persson wrote:
> From: "Thomas Kunert" <kunert@physik.tu-dresden.de>
> > ... you want to apply some algorithm, e.g. sort, on it.
> > The easiest code to do that is
> > 
> > sort( v.begin(), v.end() );
> > 
> > but given the current definition of the iterator paired with
> > unreliable optimization in the compiler this code is simply
> > irresponsible and deserves forbidden. 
> > ... Why should one
> > bet the performance of the code on the abilities of the compiler
> > if its so easy to avoid that? 
> 
> Why wouldn't one require the compiler to support common idioms?

Indeed, if the compiler is failing to optimize the case above
properly, the library is allowed to partially-specialize std::sort
(and other algorithms) for the case of vector iterators.  

Of course it would be much better for the compiler to do that 
optimization.  Furthermore, special-casing it in the library (either 
by eliminating abstraction or by specialization) reduces pressure on 
the compiler developers to do the right thing by user code which would
not benefit by those library tricks.

Nathan Myers
ncm-nospam@cantrip.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]