Advertisement

STL worth it?

Started by February 01, 2000 07:28 AM
5 comments, last by Sieggy 24 years, 10 months ago
I''ve read a little bit about it and I have only heard positive things on it but I''m curious to hear if anyone is using STL. How''s the performance? Is it a useful or does anyone find it incredibly lame? Thanks! Sieggy
I''m slightly biased here, but I have to say that unless you place NO VALUE WHATSOEVER on your own time, using STL is worth it. Why bother rewriting basic data structures and algorithms over and over when it''s been done already?

As for performance, the entire point of generic programming techniques (from which STL is built) is obtain abstraction (as OO tries to do) but without any performance penalty. The algorithms used in STL are state of the art, and unless you''re really crazy about performance, you''re unlikely to (for example) duplicate the efficiency of STL''s sort().

In short, what''s the point of using a language (C++) if you''re not going to use the bulk of its standard library?

-Brian
Advertisement
Thanks for the info Brian. I''m a big fan of OO but I have to admit I only recently started reading up on STL so I wanted to get someone else''s thoughts on it. Appreciate it!

Sieggy
Just learned STL about 6 months ago, and I''m really happy with it. One of the huge benefits is that as soon as you get the interface down (i.e. figure out how iterators work), the entire library is very easy to use.

There are two things I don''t like about it. First, if you use STL containers, you will have to do at least one copy per object--there''s just no way around it. Second, the deque is just not as cool as I thought it would be--it''s pretty damn slow if you use small objects.

Otherwise, the whole library is pretty hot. Maps and sets are just awesome. I highly recommend you add it to your personal programming toolbox.
Yes, a couple of things I overlooked. It's important to understand the design of the library if you want to get the most out of it. Most people (I think) simply see it as a bunch of containers (oh wow, a vector, big deal...) But once you realize the abstractions that make the library up (iterators, containers, functors, adaptors) and how to orthogonally connect them, you have untold power at your fingertips:

---

int main()
{
vector{string} s;
copy(istream_iterator{string}(cin),
istream_iterator{string}(),
back_inserter(s));
sort(s.begin(), s.end());
copy(s.begin(), s.end(),
ostream_iterator(cout, "\n");
return 0;
}

There. I wrote command line sort (like on UNIX). In fact, I think it can be done even shorter. But you get the point.

-Brian

PS: This is my "living" as I'm doing my graduate research with one of the primary STL creators.

Edited by - osmanb on 2/1/00 4:45:24 PM
Agreed with everything said, plus:

If you''re like me and think MSVC''s docs on STL suck, try the SGI STL docs, at:

http://www.sgi.com/Technology/STL/

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com
Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
Advertisement
Did anyone else take a quick look at the superbowl and think that Standard Template Libraries were up at the half? ( I wish I was kidding, gotta stop reading so many computer books.)

Just because STL is coming up so much lately, thought I''d post a friendly reminder that templates are a standard (if oft overlooked) part of C++. Even if you choose not to use STL, you should do yourself a favor and write your own templated class for your linked list. I personally prefer having a current node tacked on and overloaded ++ and -- for going through the records.

-the logistical one-http://members.bellatlantic.net/~olsongt

This topic is closed to new replies.

Advertisement