STL thoughts
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
i love the STL. :rolleyes: as soon as i got the hang of it, i abandoned MFC's collections totally. i use the std algorithms a lot: sort, reverse, unique, etc. i use string and wstring in many apps (especially where MFC isn't an option). i've used functors in a couple of places to do some strange stuff that would've been a hideous mess otherwise. and, i've lately found myself using small things like std::swap or std::min. i used to think STL was worthless - MFC can do a lot of the basic stuff (CStringArray, for example). but, once i really got into STL, i realized how powerful it really is. yummy. i imagine i'd get the same feeling if i ever got into the functional programming languages; but i don't have the time to learn a new language these days. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
Well, it depends on algorithm complexity. In case of strings and vectors algorithms are not prioritized - we really think of objects, not methods. But take, for example, quick sort algorithm. Then it's not important what we sort - rather how we sort (I'm oversimplified it a little, but you got the idea). What many developers forget when they start using STL - is that source code reuse has nothing to do with binary code reuse. If you declare and use vector, vector, vector, then you end up with 3 copies of API sets that implement vector functionality. (Once by reducing the number of MFC CList<> collections I managed to reduce the size of the executable by about 100K). In case classes are just slightly different, it is much more efficient to declare a vector of base class elements. If however classes have different storage size, storing by value base class objects does not work. So you end up with an vector of pointers. So like everything else, STL has its pro's and co's. Vagif Abilov COM+/ATL/MFC Developer Oslo, Norway
-
i love the STL. :rolleyes: as soon as i got the hang of it, i abandoned MFC's collections totally. i use the std algorithms a lot: sort, reverse, unique, etc. i use string and wstring in many apps (especially where MFC isn't an option). i've used functors in a couple of places to do some strange stuff that would've been a hideous mess otherwise. and, i've lately found myself using small things like std::swap or std::min. i used to think STL was worthless - MFC can do a lot of the basic stuff (CStringArray, for example). but, once i really got into STL, i realized how powerful it really is. yummy. i imagine i'd get the same feeling if i ever got into the functional programming languages; but i don't have the time to learn a new language these days. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
I love STL as well, but I understand why it scares people too. I typedef the hell out of a lot of my declarations to reduce all the template goo in my code. My own powerful STL faves: 1) Tokenizing strings into a vector from a file in one step, using ifstream, the copy algorithm and back_inserter. 2) Using for_each to call a member function on each item in a vector of object pointers. This is great for simulation programs that I work on.
-
i love the STL. :rolleyes: as soon as i got the hang of it, i abandoned MFC's collections totally. i use the std algorithms a lot: sort, reverse, unique, etc. i use string and wstring in many apps (especially where MFC isn't an option). i've used functors in a couple of places to do some strange stuff that would've been a hideous mess otherwise. and, i've lately found myself using small things like std::swap or std::min. i used to think STL was worthless - MFC can do a lot of the basic stuff (CStringArray, for example). but, once i really got into STL, i realized how powerful it really is. yummy. i imagine i'd get the same feeling if i ever got into the functional programming languages; but i don't have the time to learn a new language these days. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
I couldn't agree more - where I work I am known as the STL zealot, because I absolutely refuse to use the MFC containers now that I know some STL. It's just so flexible and powerful, I feel like I am barely scratching the surface. I have recently read that the MFC containers were only put in as a stopgap as the STL was not part of the standard at the time. I dunno if this is true or not, but I do know that compared to the STL they seem to me like tinkertoys. Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
-
I've been looking at some discussions recently on the forums regarding the C++ STL. Seems like most everyone prefers using classes because the data and methods are bound together. When the data/container is separate from most of the algorithms (as is the case with libraries like STL), then most users don't have a good idea of the capabilities of the library or forget about the algorithms. What do you think of the STL concept?
For anyone using the STL, you should get a copy the July 2001 "C/C++ Users Journal" - it has a great article by Leor Zolman on how to install a Perl filter that totally reworks the warning and error messages from STL classes. This makes a HUGE difference to working with STL under VC6 - no more of those endless messages that are impossible to decode. Or it you're too cheap to pay for a copy of the Users Journal, go straight to the source : http://www.bdsoft.com/tools/stlfilt.html
-
For anyone using the STL, you should get a copy the July 2001 "C/C++ Users Journal" - it has a great article by Leor Zolman on how to install a Perl filter that totally reworks the warning and error messages from STL classes. This makes a HUGE difference to working with STL under VC6 - no more of those endless messages that are impossible to decode. Or it you're too cheap to pay for a copy of the Users Journal, go straight to the source : http://www.bdsoft.com/tools/stlfilt.html
Great! Mike, you just hit on my biggest woe with using STL (which I love). Thanks. On the topic, does anyone know of a good *online* STL reference? I've seen a few wonderful paper versions, but it would be handy to keep something searchable on my machine- and I don't trust any of the documentation in MSDN.... Often, I come across something wonderful in STL (like the string tokenising noted above) and feel like singing and dancing... :) everyone here is a bit sus on the STL and I have to keep quiet :( The solution... an STL forum!!! I know we have a VC++ forum, but it's kind of in a different vein to what I mean... Chris? cheers NB
-
I couldn't agree more - where I work I am known as the STL zealot, because I absolutely refuse to use the MFC containers now that I know some STL. It's just so flexible and powerful, I feel like I am barely scratching the surface. I have recently read that the MFC containers were only put in as a stopgap as the STL was not part of the standard at the time. I dunno if this is true or not, but I do know that compared to the STL they seem to me like tinkertoys. Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
STL containers are great. The only problem I have with STL is mixing it with MFC GUI code. Many of the functions require a CString as inputs/outputs (e.g. GetWindowText() is a common function that comes up), and I have to pass in a temp CString to GetWindowText() and then convert that into a std::string. Sometimes that scratches me the wrong way, and annoys me like fingernails scratching on a blackboard.
-
Great! Mike, you just hit on my biggest woe with using STL (which I love). Thanks. On the topic, does anyone know of a good *online* STL reference? I've seen a few wonderful paper versions, but it would be handy to keep something searchable on my machine- and I don't trust any of the documentation in MSDN.... Often, I come across something wonderful in STL (like the string tokenising noted above) and feel like singing and dancing... :) everyone here is a bit sus on the STL and I have to keep quiet :( The solution... an STL forum!!! I know we have a VC++ forum, but it's kind of in a different vein to what I mean... Chris? cheers NB
Here is the SGI one http://www.sgi.com/tech/stl/stl\_index\_cat.html Tim Smith Descartes Systems Sciences, Inc.
-
I wonder how many people are like me and just end up using vector, set, map, and a few other assorted classes. I hardly if ever use the algorithms directly. Tim Smith Descartes Systems Sciences, Inc.
I was the same way until I started reading "Effective STL" by Scott Meyers. It's a great book. I definitely recommend it.
-
Great! Mike, you just hit on my biggest woe with using STL (which I love). Thanks. On the topic, does anyone know of a good *online* STL reference? I've seen a few wonderful paper versions, but it would be handy to keep something searchable on my machine- and I don't trust any of the documentation in MSDN.... Often, I come across something wonderful in STL (like the string tokenising noted above) and feel like singing and dancing... :) everyone here is a bit sus on the STL and I have to keep quiet :( The solution... an STL forum!!! I know we have a VC++ forum, but it's kind of in a different vein to what I mean... Chris? cheers NB
>>> [snip]...does anyone know of a good *online* STL reference? <<< I've found the following ones to be very good; Dinkum C++ Library (http://www.dinkumware.com/htm\_cpl/index.html) SGI's STL (http://www.sgi.com/tech/stl/) Ben Burnett --------- On the topic of code with no error handling -- It's not poor coding, it's "optimistic" ;)
-
STL containers are great. The only problem I have with STL is mixing it with MFC GUI code. Many of the functions require a CString as inputs/outputs (e.g. GetWindowText() is a common function that comes up), and I have to pass in a temp CString to GetWindowText() and then convert that into a std::string. Sometimes that scratches me the wrong way, and annoys me like fingernails scratching on a blackboard.
> The only problem I have with STL is mixing it with MFC GUI code. > Many of the functions require a CString as inputs/outputs (e.g. > GetWindowText() is a common function that comes up), and I have > to pass in a temp CString to GetWindowText() and then convert > that into a std::string GetWindowText(...) also allows you to take a TCHAR buffer, so you do not have to do an extra wasteful dynamic memory allocation (and free) for the CString. Yes, std::basic_string does not directly expose the internal buffer, but IIRC, that is one of the "features" of proper encapsulation. The STL containers can also manage your own string type, or even MFC's CString, if you so desire (always store pointers to objects). Peace! -=- James.
-
i love the STL. :rolleyes: as soon as i got the hang of it, i abandoned MFC's collections totally. i use the std algorithms a lot: sort, reverse, unique, etc. i use string and wstring in many apps (especially where MFC isn't an option). i've used functors in a couple of places to do some strange stuff that would've been a hideous mess otherwise. and, i've lately found myself using small things like std::swap or std::min. i used to think STL was worthless - MFC can do a lot of the basic stuff (CStringArray, for example). but, once i really got into STL, i realized how powerful it really is. yummy. i imagine i'd get the same feeling if i ever got into the functional programming languages; but i don't have the time to learn a new language these days. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
> [...]i've used functors in a couple of places to do some strange stuff > that would've been a hideous mess otherwise. Man, once I first learned about (and figured out) functors, I thought that they were the coolest idea! :) "algorithm" contains lots of cool stuff, I, too, use STL, even the allocators stuff (for preventing heap contention with multithreaded apps), quite often. Peace! -=- James.
-
Great! Mike, you just hit on my biggest woe with using STL (which I love). Thanks. On the topic, does anyone know of a good *online* STL reference? I've seen a few wonderful paper versions, but it would be handy to keep something searchable on my machine- and I don't trust any of the documentation in MSDN.... Often, I come across something wonderful in STL (like the string tokenising noted above) and feel like singing and dancing... :) everyone here is a bit sus on the STL and I have to keep quiet :( The solution... an STL forum!!! I know we have a VC++ forum, but it's kind of in a different vein to what I mean... Chris? cheers NB
We don't need an STL forum, just the courage to speak freely about STL in the face of public persecution. ;) Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
-
I wonder how many people are like me and just end up using vector, set, map, and a few other assorted classes. I hardly if ever use the algorithms directly. Tim Smith Descartes Systems Sciences, Inc.
Yes, I am like that. But I hope to improve as I learn the STL more and more. The way I see it, it is better if STL is hard to learn. I will learn it for sure, but others won't, which will make me better than the rest ;) :cool: (2b || !2b)
-
We don't need an STL forum, just the courage to speak freely about STL in the face of public persecution. ;) Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
-
We don't need an STL forum, just the courage to speak freely about STL in the face of public persecution. ;) Christian Secrets of a happy marriage #27: Never go to bed if you are mad at each other. It's more fun to stay up and fight.
-
I wonder how many people are like me and just end up using vector, set, map, and a few other assorted classes. I hardly if ever use the algorithms directly. Tim Smith Descartes Systems Sciences, Inc.
I use a number of the algorithms directly. The problem is that the way Microsoft/Dinkumware implemented STL for VC++, you can't use predicate versions of many of the algorithms (e.g., sorting can only be done using
operator >()
for a comparison operator), which makes them less than useful. Fortunately, the C++ compiler itself (if you're using SP3 or above) is capable of generating predicates, so you can rewrite the STL to comply more closely with what's documented in Saini and Musser. The real beauty will come when Microsoft finally implements partial-template-specialization, at which point the algorithms will really come into their own. He was allying himself to science, for what was science but the absence of prejudice backed by the presence of money? --- Henry James, The Golden Bowl