3

I'm confused about some of the documentation at cplusplus.com. Have I used the standard template library with either of these two lines of code?

for (std::string::const_iterator it = str.begin(); l < data.size; ++it, ++l)

and

tile_tag(): distance(std::numeric_limits<int>::max()), dir(unknown_direction), used(false)

See: http://www.cplusplus.com/reference/string/string/begin/ and http://www.cplusplus.com/reference/std/limits/numeric_limits/

If I have used STL, how can I modify them to do what they do without STL?

Thanks!

EDIT: I guess this is OUR definition of STL: http://www.sgi.com/tech/stl/stl_index_cat.html

I don't see const_iterator...but I do see max. But is that the max I used?

user618712
  • 1,463
  • 7
  • 17
  • 19
  • 3
    That website you speak of [may not be the best reference](http://programmers.stackexchange.com/questions/88241/whats-wrong-with-cplusplus-com) for all situations, I'm afraid. If you want to speak in terms of the C++ standard, you should unlearn the term "STL", which isn't part of the standard. – Kerrek SB Sep 23 '11 at 20:45
  • Depends on your definition of STL: http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about – Mark Ransom Sep 23 '11 at 20:46
  • Is a third-party forcing you to avoid some parts of the standard library? If this is a class assignment it might help to add the homework tag and add let us know the constraints you are under. – Blastfurnace Sep 24 '11 at 00:00

5 Answers5

5

Yes, you used it, since std::string alone is "part of the STL", but, more importantly, you are using the iterators, which are a distinctive trait of the STL.

Now, for the mandatory purists part: the STL was a library published by SGI and developed mainly by Alexander Stepanov. What I think you are referring to is "the part of the SGI STL which was later included into the standard with some minor modifications", i.e. all the generic containers/algorithms/iterators stuff.

The usage of the term "STL" for this stuff is tolerated, what is plain wrong, instead, is calling "STL" the whole C++ standard library (which includes a lot of other stuff, e.g. iostreams, locale, the library inherited from C, ...).

If I have used STL, how can I modify them to do what they do without STL?

Why would you want to do that? Anyhow, you have several options, that span from rewriting such classes and algorithms from scratch to using simpler data structures (e.g. C strings) reimplementing only the algorithms you need. Anyway, they both imply reinventing the wheel (and probably reinventing a square wheel), so I'd advise you against doing this unless you have a compelling reason.


EDIT: I guess this is OUR definition of STL: http://www.sgi.com/tech/stl/stl_index_cat.html

Are you sure? Almost no one today uses the SGI STL, generally you use the (more or less) equivalent portion of your C++ standard library (that, by the way, is what you are doing in your code, since you are getting everything from the std namespace).

I don't see const_iterator...

const_iterator is a typedef member of basic_string<char>, you find it in its page.

but I do see max. But is that the max I used?

No, it's not it, your max is not a global function, but a member of the std::numeric_limits template class. Such class do not come from the STL.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • +1 for finally addressing the confusion here between STL and std. Its either C++'s string and STL, or char*s and counters. You could even `#include` a string header from your C implementation. – Niall Cairns Sep 23 '11 at 20:57
  • AWESOME! Then based on HIS definition of STL, I am safe. My max is not part of STL on that SGI page. AND he said we could use string! – user618712 Sep 23 '11 at 22:09
2

Does your code include the namespace std? Then yes, you have used the Standard library. How you can you modify your code to not use the Standard library? Why on earth would you want to? Implementations must provide it- that's why it's called Standard. But if you're truly insane and feel the need to not use it, then ... look up the documentation on what those functions and classes do and write your own replacement.

Puppy
  • 144,682
  • 38
  • 256
  • 465
2

You have used the STL std::string and std::numeric_limits. I don't know why you would want to avoid using STL (perhaps homework?). You could use old style C strings with a char* and the macro definition MAX_INT from C limits.

K-ballo
  • 80,396
  • 20
  • 159
  • 169
1

What is this "STL" you speak of?

There was this thing that SGI developed in the mid 90s. Yeah, that's 15+ years ago. Older than the previous C++ standard. Back in the days when compilers like Turbo C++ and Borland C++ were best-of-breed; when people used the phrase "C with classes" unironically and without derision; when the idea of compiling C++ primarily by first cross-compiling to C was finally being abandoned; when exceptions were (at least in this context!) a new idea.

They called it "STL" for "standard template library", and they were doing a bunch of neat things with templates and developing new idioms. For its time, it was pretty revolutionary. So much so, in fact, that almost all of its stuff got officially accepted into the standard library with the 1999 standardization of the language. (Similarly, lots of Boost stuff - although nowhere near all; Boost is huge - has been added to the std namespace in the new standard.)

And that's where it died.

Unless you are specifically referring to a few oddball things like std::iota or lexicographical_compare_3way, it is not appropriate to speak of "the STL", and it hasn't been appropriate to speak of "the STL" for twelve years. That's an eternity in computer science terms. (But, hell, I still seem to keep hearing about new installations of Visual C++ 6.0, and some people using even older compilers...)

You're using the standard library of the C++ language. I guess you could write "SC++L" if you like, but that's a bit awkward, isn't it? I mean, no sane Java programmer would ever refer to the SJL, nor any Pythonista to the SPL. Why would you need jargon to talk about using the standard library of the language you are using?

This is what you're supposed to do by default, after all. Could you imagine writing code in C without malloc, strlen et. al.? Avoiding std::string in C++ would be just as silly. Sure, maybe you want to use C++ as a systems programming language. But really, the kinds of applications where you absolutely have to squeeze out every cycle (keep in mind that using std::string is often more efficient than naive string algorithms, and difficult to beat with hard work, because of the simple algorithmic benefits of caching the string length count and possibly over-allocating memory or keeping a cache for short strings) are generally not ones that involve string processing.

(Take it from me - I have several years' experience as a professional mobile game developer, dating to when phones were much, much less powerful: the standard approach to string processing is to redesign everything to need as little of it as possible. And even when you do have to assemble - and line-wrap - text, it was usually not worth optimizing anyway because the time the code spends on that is dwarfed by the time it takes to actually blit the characters to screen.)

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • So you're saying that all those books like "Effective STL", and the constant references to "the STL" made by a variety of C++ committee members are all wrong? I'm sorry, but I'm inclined to trust Herb Sutter before you. If the term "STL" is good enough for the chairman of the C++ standardization committee, it's good enough for me. – jalf Sep 23 '11 at 21:35
  • To be clear, the SGI library is irrelevant today. But the term STL is commonly used, and for good reason, to describe the STL-derived subset of the C++ standard library. I see no reason not to use "STL" for that purpose, even though the C++ standard contains no mention of the term. – jalf Sep 23 '11 at 21:36
  • "Effective STL" dates to 2001, and was written by Meyers, not Sutter. Sutter does appear to have used the term "STL" fairly recently per Google, but this isn't something that can be made right or wrong by authority, anyway. My argument is that making any attempt to refer specifically to "the STL-derived subset of the C++ standard library" is, except perhaps in some specific language-historical discussions, counterproductive at best (as it suggests that there's something special or interesting about using **the standard library of the language you're using**) and confusing at worst. – Karl Knechtel Sep 25 '11 at 04:41
  • my argument is that you're wrong. ;) Why is it counterproductive to talk about the part of the standard library that everyone agrees is the best designed, which has guided the evolution of the language and of many other libraries, and, not least, which has a separate flavor from other parts of the stdlib? Why shouldn't I be able to ask "how do I use the STL part of the stdlib"? Suppose I'm not interested in how to use cout or strtok or the other non-STL parts? – jalf Sep 25 '11 at 10:32
  • It is counterproductive to pretend that some big insurmountable ambiguity exists which automatically renders any use of the term "STL" void. It is counterproductive to **prevent people from discussing something that has relevance today, in order to prevent some nonexistent, but imagined by a few pedants, ambiguity with something that has had zero relevance for 15 years**. – jalf Sep 25 '11 at 10:33
  • And if you think there is nothing special or interesting about the STL subset of the standard library, then I can only assume that you have never used it. Funnily enough, I've talked to a lot of people, newbies and seasoned C++ devs alike, and I've only encountered two people who *claimed* to be confused by the term. You and @Tomalak, both of whom are *not* confused, because you both obviously know the full history of the STL, **but you are so absorbed in your "I'm more pedantic than thou"-masturbation that you don't realize this so-called confusion *does not exist*. – jalf Sep 25 '11 at 10:33
  • If you want to argue otherwise, I don't care. You're wrong. That's really all there is to it. Communication is a pretty major part of programming, and communication is easier if we have a word for something than if we don't. So being able to use the term "STL" makes it easier for us to discuss "the STL", than if we ban the term and force people to talk about the *entire* stdlib or say nothing at all. This isn't about "confusion", and it isn't about bieng "counterproductive", it is about your goddamn thought police. Why do you feel that you should dictate what people are allow to discuss? – jalf Sep 25 '11 at 10:38
  • Oh, and "this isn't something that can be made right or wrong by authority"? The hell it is. See, you think this is some hypothetical discussion about "does the standard make mention of "the STL". Of course it doesn't. But the rest of us are discussing something entirely different: "what do C++ programmers mean when they say "STL". The standard doesn't have to acknowledge the term in order for it to be meaningful. The standard doesn't mention a stack, but C++ programmers are quite familiar with it anyway, and able to talk about it without being "confusing" or "counterproductive". – jalf Sep 25 '11 at 10:43
  • The standard doesn't mention the OS, it doesn't mention network programming, there are a million things relevant to C++ development that the standard does not define. So f'ing what? We still know they exist, we still have names for them, and we still talk about them. And the same is true for the STL. – jalf Sep 25 '11 at 10:45
  • Not at all. But it annoys me when people get so lost in C++-pedantry that they completely lose sight of the real world – jalf Sep 26 '11 at 09:18
0

"STL" can mean a number of things.

Formally, the name "STL" was only ever used for the library developed by Stepanov, and which is now hosted by SGI. The library consisted, roughly speaking, of containers (vector, list, deque, map, set and all those), iterators and algorithms (and a few other bits and pieces, such as allocators)

This library was adopted and adapted into the C++ standard library when the language was standardized in 1998. In this process, a number of changes were made: corners were cut, components were left out, in order to keep the library small, and to make it easy to swallow for the committee members. A number of changes in order for it to better interoperate with the rest of the standard library, or with the language itself, and certain parts of the existing standard library were modified to become a bit more STL-like.

Today, it's really not very useful to discuss the original STL. So when most C++ developers say "STL", they mean "the part of the C++ standard library that was created when the STL was adopted into the standard". In other words, all the container classes, the iterators and the algorithms in the standard library, are commonly called "STL", simply because they look a lot like the "original" STL, and they're a lot more relevant today than the original library.

But this also means that the term has become rather fluffy and vague. The std::string class was not a part of the original STL. But it was modifed to behave "STL-like". For example, it was given iterators, so that it can be used with the STL algorithms. Should it be considered a part of the STL? Maybe, maybe not.

And to forther confuse matters, the STL became fashionable after it was adopted into the language. Suddenly, people started talking about "STL-style". The Boost libraries, for example, are generally written in a very STL-like way, and some Boost libs have been adopted into the standard library in C++11. So should they now be considered part of the STL?

Probably not, but you could make a pretty good case that they should: that they follow the spirit of the STL, and if Stepanov had thought of them when he write the original STL library, maybe he'd have included them.

Except for a few purists, who think that everyone is better off if the term "STL" is used exclusively to refer to something that no one ever actually needs to refer to (the SGI library), and if we have no way to refer to the standard library subset that it spawned, pretty much any C++ developer can agree that if you've used the standard library containers OR the standard library iterators OR the standard library algorithms, then you have used the STL.

In your code I see an iterator. So yes, you've used at least a small corner of the STL.

But why does it matter?

jalf
  • 243,077
  • 51
  • 345
  • 550