Slimelite BBS

stl

Back to EMULATE

From Chris Downs · 1996-04-04 16:32 · #73535 in EMULATE

 DM> I understand the concept of templates, but I'm
 DM> not really that proficient in their proper use.

 Well, I just started with STL a few weeks ago and it doesn't take
 very long to use the STL to great benefit.  The biggest hurdle was
 getting the darn thing set up.  I had to modify the STL source,
 figure out how to set up the header declarations, and then
 it took way too long to find the place in the setttings tabbed
 dialog to tell the compiler where to search for system headers.
 (On line docs suck unless you already know what you are looking
 for.) An lets not forget that damn NOMINMAX declaration.

 My suggestion...  Start with the vector template. Use it
 whereever you've been using arrays. (Except for char arrays
 when it really makes sense to use some sort of string class.)
 Since there are operations that work the same across container
 types, this will get you used to using the STL.  And once
 you start enjoying the features of an array that dynamically
 grows as you need it, you'll wonder why you were ever hard coding
 array sizes (let's guess the worst case) in the first place.

 DM> However, I *do* realize that
 DM> there is a lot of code that I really *shouldn't* have to
 DM> reinvent, such as those standard containers (lists, queues,
 DM> binary trees, etc.) because they've been done so many times
 DM> in so many places that it hurts.  :-)

 Yep.  And there are not just containers, but algorithms involved too.
 How about sorting a vector like this....

 std::vector<int> vect; //Hey Jerry! It won't work without the std::
 vect.push_back(5);
 vect.push_back(4);
 //lots of other additions to vect.
 sort (vect.begin(), vect.end()); // pretty easy to sort!

 To sort a "real class" requires one "comparison function object" be
 declared so that the STL knows what (a < b) means.

 DM> I take it by the name, though, it'll likely be good both as
 DM> beginner in it and when (if) I become proficient and just
 DM> need to look up a few things ("what order are those
 DM> parameters again?").

 Yep.  And since there's no on-line help, you're going to need
 some sort of reference.  But parameter order isn't so hard to
 get used to.  It's quite consistent for how functions get
 called.

 DM> The Tutorial part - it has examples that I can type in with
 DM> basically any compiler, get it to work, and get some 'hands
 DM> on' type of experience?  Guess how I learn the best... :-}

 It certainly won't be an "any compiler" deal.  For MS, you need
 special tweeking and the same goes for Borland.  Nelson's book
 has Borland examples because when it was written, the MS version
 couldn't support STL.  You'll need compiler specific info for
 how to use STL.  And for me, that really was the hardest part.

 Once it's up and running, STL makes a lot of tedium simply
 disappear.  Take the time to learn how to use STL.  You'll
 write code faster.  One extra advantage is that you'll impress
 your co-workers when you are up to snuff on the latest and
 gretest while they're still stuck implementing linked lists
 by hand.....



--- WILDMAIL!/WC v4.12 
 * Origin:   (1:100/4.0)