stl

C++ STL make_heap and pop_heap not working.

I need to use a Heap, so i've searched about the STL one, but it doesn't seem to work, i wrote some code to explain what i mean: #include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm> struct data { int indice; int tamanho; }; bool comparator2(const data* a, const data* b) { return (a->tamanho < b->t...

C++ Mutexes and STL Lists Across Subclasses

I am currently writing a multi-threaded C++ server using Poco and am now at the point where I need to be keeping information on which users are connected, how many connections each of them have, and given it is a proxy server, where each of those connections are proxying through to. For this purpose I have created a ServerStats class wh...

Is std::pair<int, std::string> ordering well-defined?

It seems that I can sort an std::vector<std::pair<int, std::string>>, and it will sort based on the int value. Is this a well defined thing to do? Does std::pair have a default ordering based on it's elements? ...

std::string insert method has ambiguous overloads?

Environment: VS2005 C++ using STLPort 5.1.4. Compiling the following code snippet: std::string copied = "asdf"; char ch = 's'; copied.insert(0,1,ch); I receive an error: Error 1 error C2668: 'stlpx_std::basic_string<_CharT,_Traits,_Alloc>::insert' : ambiguous call to overloaded function It appears that the problem is the in...

Sanity Check - will a stl::Container of new'd objects each be deleted when the container itself dies?

Title pretty much covers it. If I've added say 3 objects to a list and the list goes out of scope and dies, will it call delete on each entry before going out of scope? Pretty sure yes, but getting tired and need a sanity check. ...

What is so great about STL?

Hello StackOverflow. I am a Java developer trying to learn C++. I have many times read over the web (including StackOverflow) that STL is the best collections library that you can get in *any* language. (Sorry, I do not have any citations atm) However after studying some STL, I am really failing to see what makes STL so special. Would...

Does tbb:concurrent_queue "grow" like std::vector? How to release its buffers?

Hello, I'm wondering if tbb:concurrent_queue can grow its internal buffers when it's under high load, and then not release the buffers? How to obtain any information about the buffers and/or release them? PS. In vector, you have methods like .reserve() to allocate and .swap(vector()) to completely release any buffers. ...

STL Rope - when and where to use

I was wondering under what circumstances you would use a rope over another STL container? ...

Why only random-access-iterator implements operator+ in C++?

I'd like get far next value for STL list iterator but it doesn't implement operator+, vector has it though. Why and how can I get the value where I want? I think I can do that if I call operator++ several times, but isn't that a little bit dirty? What I want to do is the following: list<int> l; ...omitted... list<int>::iterator itr = ...

Need help with map (c++, STL)

Hi folks! Actually I'm new to C++. I tried something out (actually the map container) but it doesn't work the way I assumed it will... Before posting my code, I will explain it shortly. I created 3 classes: ClassA ClassDerivedA ClassAnotherDerivedA The two last ones are derived from "ClassA". Further I created a map: map<stri...

STL list - how to find a list element by its object fields

I have a list: list<Unit *> UnitCollection; containing Unit objects, which has an accessor like: bool Unit::isUnit(string uCode) { if(this->unitCode == uCode) return true; else return false; } How do I search my UnitCollection list by uCode and return the corresponding element (preferably and iterator). In ...

C++ map performance - Linux (30 sec) vs Windows (30 mins) !!!

I need to process a list of files. The processing action should not be repeated for the same file. The code I am using for this is - using namespace std; vector<File*> gInputFileList; //Can contain duplicates, File has member sFilename map<string, File*> gProcessedFileList; //Using map to avoid linear search costs void processFile(Fi...

How to call a method via a vector?

Hi! How do I call a method of an object which is stored within a vector? The following code fails... ClassA* class_derived_a = new ClassDerivedA; ClassA* class_another_a = new ClassAnotherDerivedA; vector<ClassA*> test_vector; test_vector.push_back(class_derived_a); test_vector.push_back(class_another_a); for (vecto...

C++ STL map.find() not finding my stuff

Hello, I have constructed a map and loaded it with data. If I iterate over all the elements I see they are all valid. However, the find method doesn't find my item. I'm sure it's something stupid I am doing. Here is snippet: // definitions // I am inserting a person class and using the firstname as the key typedef std::map<char*,Per...

creating a vector with references to some of the elements of another vector

hi, I have stored instances of class A in a std:vector, vec_A as vec_A.push_back(A(i)). The code is shown below. Now, I want to store references some of the instances of class A (in vec_A) in another vector or another array. For example, if the A.getNumber() returns 4, 7, 2 , I want to store a pointer to that instance of A in another...

accessing nth element (value) of a vector after sorting

dear experts, This question is an extension of this question I asked. I have a std::vector vec_B.which stores instances of class Foo. The order of elements in this vector changes in the code. Now, I want to access the value of the current "last element" or current 'nth' element of the vector. If I use the code below to get the last ...

C++ Standard Library Exception List??

Hi, Is there a reference about C++ Standard Library Exceptions? I just want to know that which functions may throw an exception or not. Thank you. ...

map::lower_bound that returns a map

Is there a function that does the same thing as map::lower_bound except it returns a new sub-map and not an iterator? Edit: The function should return a sub-map which contains all the values for which the key is equal to, or greater than a certain value (which is given as input to the function). ...

C++ iterator and const_iterator problem for own container class

Hi there, I'm writing an own container class and have run into a problem I can't get my head around. Here's the bare-bone sample that shows the problem. It consists of a container class and two test classes: one test class using a std:vector which compiles nicely and the second test class which tries to use my own container class in ex...

Use of for_each on map elements

I have a map where I'd like to perform a call on every data type object member function. I yet know how to do this on any sequence but, is it possible to do it on an associative container? The closest answer I could find was this: Boost.Bind to access std::map elements in std::for_each. But I cannot use boost in my project so, is there ...