[Gllug] OT(ish): Advice

Nix nix at esperi.demon.co.uk
Wed Dec 18 23:20:27 UTC 2002


On Tue, 17 Dec 2002, Jonathan Harker stipulated:
> On Monday 16 Dec 2002 7:17 am, Nix wrote:
>> (Actually, I disagree here; unless profiling shows an inefficiency hit,
>> I prefer to use the algorithm for ease of movement of code between
>> different containers. Your code should ideally not care what container
>> it's implemented above, but should just care about iterators --- and
>> algorithmic complexity of course.)
> 
> You should never rely on being able to change your containers around 
> willy-nilly

Whyever not? 

Obviously you can't easily change between containers that model
different things, but changing between, say, a list<> and a deque<>
should be fine; they even have similar complexities. (Even list<> to
vector<> should be reasonable.)

Of course the right thing to do on the efficiency front is for the
implementation to define specializations of the appropriate algorithms
that use the vector operations (using iterator tags to determine which
is which, as usual). This is a QoI thing, and if your implementation
doesn't get it right, switch to one that does.

I'm also not sure what you meant when you referred to `vector.copy()',
as this method doesn't exist. The only specialized algorithm the
Standard defines for vector<> is swap(), and, well, in decent
implementations either that's defined in terms of (a specialization of)
the swap() algorithm, or the algorithm's specialization is defined in
terms of vector.swap(), or both (as is done in libstdc++).

>             - again cf. Effective STL (I forget the item number, and I also 
> forget the rationale, but it made perfect sense at the time. Don't you hate 
> it when you remember stuff, but can't remember the reasons? It makes for 
> really lame debating! :-)

Yep :)

I haven't read Effective STL yet, anyway; I haven't been able to find a
copy. I really should look harder.

-- 
`I was thinking of the legendary British Weather, with the four seasons
 of winter, mud, rain, and damp.' --- Peter da Silva

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list