[Gllug] OT(ish): Advice

Jonathan Harker jharker at massey.ac.nz
Wed Dec 11 20:27:30 UTC 2002


On Thursday 12 Dec 2002 12:05 am, rich at annexia.org wrote:
> On Wed, Dec 11, 2002 at 08:44:11AM +0000, Nix wrote:
> > ... and what to do when designing a framework of generic algorithms and
> > containers.
> >
> > Your challenge: rewrite the STL above a language with less expressive
> > power (other than Ada, where it's been done, mostly). :)
>
> ----------------------------------------------------------------------
> #include <vector>
> #include <algorithm>
> main ()
> {
>   vector<int> v;
>   v.push_back (10);
>   vector<int> w;
>   copy (v.begin (), v.end (), w);
> }

<disclaimer>
I don't want to start a C++ vs. world+dog jihad. BUT...
</disclaimer>

First of all, C++ does not assume int, and hasn't for over a decade. That is a 
filthy C habit. Use int main()

Secondly, don't use an algorithm when you can use a container member function 
instead, it's more efficient in this case to use vector.copy(). cf. 
"Effective STL", Scott Meyers, Addison-Wesley.

Complaining about compiler warnings in poorly written C++ programs does not 
count against the STL, especially when you use -Wall. Why? If you know what 
you're doing, you can ignore most warnings, which is precisely why they are 
warnings and not errors. For instance, if you bring your program into the 
21st Century and use int main(), you'll get a warning that main() does not 
return a value. So what?

Anyway, Tet's point was that you can't do anything as powerful, efficient and 
generally cool as the STL in VB or C# (although with a single inheritance 
tree the need for templates is lessened).

Luv Jon

-- 
Jonathan Harker
MUSAC
Massey University
http://www.massey.ac.nz/

Any stone in your boot always migrates against the pressure gradient to
exactly the point of most pressure.
		-- Milt Barber


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




More information about the GLLUG mailing list