Questions tagged [stl]

About the "Standard Template Library", which inspired the major parts C++ Standard Library

The Standard Template Library (STL) is a software library for the programming language that influenced many parts of the C++ . It provides four components called algorithms, containers, functions, and Iterators.

28 questions
37
votes
10 answers

What is the point of using lists over vectors, in C++?

I've run 3 different experiments involving C++ lists and vectors. Those with vectors proved more efficient, even when a lot of insertions in the middle were involved. Hence the question: in which case do lists make more sense than vectors? If…
Marek Stanley
  • 481
  • 1
  • 4
  • 5
31
votes
3 answers

What difference is there between using a struct and a std::pair?

I am a C++ programmer with limited experience. Supposing I want to use an STL map to store and manipulate some data, I would like to know if there is any meaningful difference (also in performance) between those 2 data structure approaches: Choice…
Marco Stramezzi
  • 665
  • 2
  • 6
  • 16
25
votes
7 answers

Should the STL be avoided in large applications?

This might sound as a weird question, but in my department we are having trouble with following situation: We are working here on a server application, which is growing larger and larger, even at the point that we are considering to split it into…
Dominique
  • 1,705
  • 2
  • 14
  • 24
21
votes
6 answers

Is it practical to abandon STL in C++ development?

I know in some areas (game industry, for example), STL is not recommended. So my question is: is it really a good practice not to use STL in some cases? If so, what's the biggest reasons of not using the modern C++'s STL?
CaptainJH
  • 409
  • 1
  • 3
  • 5
19
votes
3 answers

QT-C++ vs Generic C++ and STL

Been brushing up on my C++ lately, on Ubuntu QQ. I love the Qt framework for everything, especially building GUI's. I became quite familiar with it when using PyQt over the last few years. When using PyQt, I had some issues that are now more…
Vector
  • 3,180
  • 3
  • 22
  • 25
17
votes
1 answer

How did std::vector come about?

Today, virtually all C++ developers agree that std::vector was a mistake since it is deceivingly not a container, and its use cases largely overlap with those of std::bitset anyway. How did it get voted into the standard? Was it controversial…
xcvii
  • 281
  • 2
  • 6
11
votes
5 answers

How to design exceptions

I'm struggling with a very simple question: I'm now working on a server application, and I need to invent a hierarchy for the exceptions (some exceptions already exist, but a general framework is needed). How do I even start doing this? I'm thinking…
Dominique
  • 1,705
  • 2
  • 14
  • 24
8
votes
2 answers

What's wrong with statically linking the STL into multiple shared libraries?

Here is the scenario: libA.so and libB.so both statically link to the same STL. libA.so has a public API that returns a std::string. libB.so calls this function and receives a copy of the string. When libB.so's copy of the string goes out of scope…
user1509041
  • 101
  • 1
  • 3
7
votes
3 answers

Are there languages that expand on the STL's iterator types?

Many languages use the concept of an iterator. The c++ STL expands on this with input iterators, output iterators, forward, bidirectional, random access and others. As far as I know, these distinctions don't exist in other languages. In this talk…
Matthew Finlay
  • 493
  • 2
  • 8
5
votes
4 answers

Why is using classic for loops as iterators in stl considered bad?

I've read a couple of articles (example) that consider the classic for (int ...... size() .... i++) loop bad practice when iterating through for example vectors in stl. Instead the recommended why is to use vector iterators, i.e. begin, end,…
Karlth
  • 243
  • 1
  • 2
  • 5
4
votes
2 answers

Differences between streams and iterators in C++?

I'm working on code which will provide a generic C++ interface to relational datasets. Some of the data will be in tables in memory (e.g. std::set or std::vector), but some of it will be computed - either produced by a function computing results of…
Dennis
  • 196
  • 1
  • 6
4
votes
1 answer

How does a priority_queue maintain a heap on a deque efficiently?

In the C++ STL, priority_queue (heap) can be used with any underlying container, such as a deque. How does the implementation stay O(log n) if deques don't swap an item in index a with index b in constant time?
Jakob Weisblat
  • 699
  • 5
  • 19
4
votes
4 answers

What kind of interface should a double container offer?

I want to write a class which offers two sequences of elements to its users. The first one (lets call it "primary") is the main of the class and will be use 80% of the time. The second one (lets call it "secondary") is less important, but still need…
authchir
  • 370
  • 3
  • 12
3
votes
1 answer

When was STL formally introduced into C++ standard?

I fail to infer the exact point of historical introduction of STL into actual C++ standard library from the wikipedia article: https://en.wikipedia.org/wiki/Standard_Template_Library It appears to me that C++11 was somehow significant for this STL,…
3
votes
1 answer

Does Microsoft still have C++ container limitations when passing to DLLs?

Microsoft has had a fair amount of trouble in the past when passing STL containers like string and vector pointers and references to DLLs. See, for example, You may experience an access violation when you access an STL object through a pointer or…
user118658
1
2