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...
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...
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?
...
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...
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.
...
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...
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.
...
I was wondering under what circumstances you would use a rope over another STL container?
...
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 = ...
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...
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 ...
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...
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...
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...
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...
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 ...
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.
...
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).
...
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...
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 ...