stl

VS2008 -> VS2010 leads to cryptic STL errors

The following C++ library was successfully compiled in VS2008 http://sourceforge.net/projects/xmlrpcc4win/files/xmlrpcc4win/XmlRpcC4Win1.0.8.zip/download When I open it in VS2010, it goes through the conversion wizard process without any errors. Now, when I attempt to compile it in VS2010, I get some weird STL errors like these: 1>Ti...

Type or Vector for representing points\positions

Hi Folks, I have a series of points\positions that won't change. Should I represent as Vector of ints or as a new type? My preference at the moment is to go with vector: doSomething(myVec[0], myVec[1] ); doSomethingElse(myVec[2], myVec[3] ); as opposed to: doSomething( myType.getPos1(), myType.getPos2() ); doSomethingElse( myTyp...

Efficiency of the STL priority_queue

I have an application (C++) that I think would be well served by an STL priority_queue. The documentation says: Priority_queue is a container adaptor, meaning that it is implemented on top of some underlying container type. By default that underlying type is vector, but a different type may be selected explicitly. and Priority...

C++0x threading

With the advent of threading facilities in the STL for the new C++ standard (C++0x), will it be better to change existing code that is using POSIX threading or even Windows threading to use STL threading? ...

How large does a collection have to be for std::map<k,v> to outpace a sorted std::vector<std::pair<k,v> >?

How large does a collection have to be for std::map to outpace a sorted std::vector >? I've got a system where I need several thousand associative containers, and std::map seems to carry a lot of overhead in terms of CPU cache. I've heard somewhere that for small collections std::vector can be faster -- but I'm wondering where that line...

Struct containing a Map in a Map? (C++/STL)

I was wondering if it was possible to create a struct containing a number of variables and a map in a map. What I have at the moment: typedef std::map<std::string,double> lawVariables; struct ObjectCustomData { std::string objectType; bool global_lock; std::map<std::string, lawVariables> lawData; }; This struct...

how to get stl map to construct/destruct inserted object only once.

I have found a very prejudicial fact about stl maps. For some reason I cant get objects being inserted in the map to get constructed/destructed only once. Example: struct MyObject{ MyObject(){ cout << "constructor" << endl; } ~MyObject(){ cout << "destructor" << endl; } }; int main() { std::map<int, ...

Can I use vector in a map in STL?

Can I declare a map like this map<string, vector<string>> mymap; I thought it is applicable. However, it shows not. I tried map<string, vector<string>*> mymap; and then it is OK What's the rule of this? ...

C++'s unordered_map / hash_map / Google's dense_hash - how to input binary data (buf+len) and insert operation.

Hi all, I have two questions about Google's dense_hash_map, which can be used instead of the more standard unordered_map or hash_map: How do I use an arbitrary binary data memory segment as a key: I want a buffer+length pair, which may still contain some NUL (\0) characters. I can see how I use a NUL-terminated char * string , but tha...

Refactoring a "dumb" function into generic STL-style with iterators to containers

I've managed to wrap my head around some of C++'s functional capacities (for_each, mapping functions, using iterators...) but the construction of the templates and function argument lists for taking in generic containers and iterators still eludes me. I have a practical example I'm hoping someone can illustrate for me: Take the followin...

why there is no find for vector in C++

what's the alternative? Should I write by myself? ...

C++'s std::string pools, debug builds? std::string and valgrind problems

Hello, I have a problem with many valgrind warnings about possible memory leaks in std::string, like this one: 120 bytes in 4 blocks are possibly lost in loss record 4,192 of 4,687 at 0x4A06819: operator new(unsigned long) (vg_replace_malloc.c:230) by 0x383B89B8B0: std::string::_Rep::_S_create(unsigned long, unsigned long, std::...

STL: writing "where" operator for a vector.

Hello, I need to find the indexes in the vector based on several boolean predicates. ex: vector<float> v; vector<int> idx; idx=where( bool_func1(v), bool_func2(v), ... ); What is the way to declare **where** function, in order to use the several user defined boolean functions over the vector? thanks Arman. Edit after one week I...

Visual Studio C++ list iterator not decementable

I keep getting an error on visual studio that says list iterator not decrementable: line 256 My program works fine on Linux, but the Visual Studio compiler throws this error. Anyway, do you see what my problem is? #include <iostream> #include <fstream> #include <sstream> #include <list> using namespace std; int main(){ /** crea...

Using memcpy in the STL

Why does C++'s vector class call copy constructors? Why doesn't it just memcpy the underlying data? Wouldn't that be a lot faster, and remove half of the need for move semantics? I can't imagine a use case where this would be worse, but then again, maybe it's just because I'm being quite unimaginative. ...

function objects versus function pointers

Hi All, I have two questions related to function objects and function pointers, Question : 1 When I read the different uses sort algorithm of STL, I see that the third parameter can be a function objects, below is an example class State { public: //... int population() const; float aveTempF() const; //....

C++: vector to stringstream

I want to know if it is possible to transform a std::vector to a std::stringstream using generic programming and how can one accomplish such a thing? ...

hash_map and stdext:: hash_map?

Under the visual C++, we have " hash_map" and "hash_set". In g++, we have " stdext::hash_map" and " stdext::hash_set". Is there any difference in terms of their respective performance or other factors? ...

Compilation errors calling find_if using a functor

We are having a bit of trouble using find_if to search a vector of pairs for an entry in which the first element of the pair matches a particular value. To make this work, we have defined a trivial functor whose operator() takes a pair as input and compares the first entry against a string. Unfortunately, when we actually add a call to...

How to call operator<< on "this" in a descendant of std::stringstream?

class mystream : public std::stringstream { public: void write_something() { this << "something"; } }; This results in the following two compile errors on VC++10: error C2297: '<<' : illegal, right operand has type 'const char [10]' error C2296: '<<' : illegal, left operand has type 'mystream *const ' Judging fro...