stdmap

Crash when utilising a std:map

In my SDL program, I am using a map construct to simulate an "infinite" array of objects within a certain class. The code manages to compile fine, but when I run the program, as soon as one of the functions using the maps is trigger, the program crashes, returning a value of 3. So, here's exactly what I'm doing: class MyClass { pu...

How to get the first n elements of a std::map

Since there is no .resize() member function in C++ std::map I was wondering, how one can get a std::map with at most n elements. The obvious solution is to create a loop from 0 to n and use the nth iterator as the first parameter for std::erase(). I was wondering if there is any solution that does not need the loop (at least not in my ...

Thread safety of std::map for read-only operations.

I have a std::map that I use to map values (field ID's) to a human readable string. This map is initialised once when my program starts before any other threads are started, and after that it is never modified again. Right now, I give every thread its own copy of this (rather large) map but this is obviously inefficient use of memory and...

Is there any generic vesion of HashTable?

I need a class that will work like C++ std::map. More specifically, I need such a behavior: map< string, vector<int> > my_map; Is it possible? ...

C++: shallow/deep copy of std::map

How would I best implement these? I thought of something like this: using namespace std; shape_container shape_container::clone_deep () const { shape_container* ptr = new shape_container(); copy( data.begin(), data.end(), (*ptr).begin() ); return *ptr; } shape_container shape_contai...

How to initialise a std::map once so that it can be used by all objects of a class?

Hi, I have an enum StackIndex defined as follows: typedef enum { DECK, HAND, CASCADE1, ... NO_SUCH_STACK } StackIndex; I have created a class called MoveSequence, which is a wrapper for a std::deque of a bunch of tuples of the form <StackIndex, StackIndex>. class MoveSequence { public: void AddMove( ...

Java equivalent of C++ std::map?

I'm looking for a Java class with the characteristics of C++ std::map's usual implementation (as I understand it, a self-balancing binary search tree): O(log n) performance for insertion/removal/search Each element is composed of a unique key and a mapped value Keys follow a strict weak ordering I'm looking for implementations with o...

Can't create map of MoveConstructibles

Hello, I have a class containing a std::unique_ptr<> and I want to put instances of this class inside of an std::map<>. I thought one of the things that motivated the introduction of move semantics to C++ was the possibility of putting things like unique_ptrs inside standard containers (and that really works, in the case of vectors). Bu...

Boost.Bind to access std::map elements in std::for_each

I've got a map that stores a simple struct with a key. The struct has two member functions, one is const the other not. I've managed calling the const function using std::for_each without any problems, but I've got some problems calling the non-const function. struct MyStruct { void someConstFunction() const; void someFunction(); };...

VS2010 RC - only 100 std::map elements in debugger

Hi, I have a small problem during debugging my App in VS 2010 RC when I want to see all the elements of std::map container. When debugger reaches the breakpoint and I want to check the values of the map in element inspector (in 'Locals' windows and in pop-up windows after hovering the variable name with mouse as well) and I'm scrolling ...

std::map default value

Is there a way to specify the default value std::map 's operator[] returns when an key does not exist? Thanks! ...

Deleting an std::map (Visual C++)

Hi, I have a pointer to a map that I am trying to delete (this map was allocated with new). This map is valid I think, when I hover on it while debugging, it shows pMap: [0]() .. When I try to delete this empty map, my app just quits and I get a First-chance exception at 0xsomelocation in myapp.exe: 0xsomenumber: The object invo...

Why isn't copy constructor being called like I expect here using map?

I am having problems using my custom class with a std::map. The class dynamically allocates memory for members, and I do not want to use pointer in the map because I want to ensure that the class takes care of deleting all allocated memory. But the problem I am having is after I add item to map, when that block of code goes out of scop...

Can't access a map member from a pointer

Hi. That's my first question :) I'm storing the configuration of my program in a Group->Key->Value form, like the old INIs. I'm storing the information in a pair of structures. First one, I'm using a std::map with string+ptr for the groups info (the group name in the string key). The second std::map value is a pointer to the sencond st...

How to convert a sorted std::list of std::pair to a std::map

Hello! I have got a std::list< std::pair<std::string,double> >, which I know is sorted according to the std::string element. Since I would like to do a lot of std::find_if based on the std::string element, I believe a std::map<string,double,MyOwnBinaryPredicate> with lower_bound and upper_bound would be more adequate. The fact is tha...

std::map and -fno-implicit-templates

I am trying to compile with g++ 4.4 and link a simple program that uses the STL. I am trying to do it using the -fno-implicit-templates so all templates must be instantiated explicitly. I don't understand why this code works: #include <map> //template class std::map<char,char>; template class std::_Rb_tree<char, std::pair <char const, ...

Using a (mathematical) vector in a std::map

Related: what can I use as std::map keys? I needed to create a mapping where specific key locations in space map to lists of objects. std::map seemed the way to do it. So I'm keying a std::map on an xyz Vector class Vector { float x,y,z } ; , and I'm making a std::map<Vector, std::vector<Object*> >. So note the key here is not ...

std::map and _CrtIsValidHeapPointer error

i try to use the std::map with class DEMO { public: DEMO(); virtual ~DEMO(); DEMO &operator =(const DEMO &d); DEMO(const DEMO& d); BYTE* Arr() const; private: BYTE *m_array; }; DEMO &DEMO::operator =(const DEMO &d) { memcpy(m_array, d.Arr(), 1); return *this; } DEMO::DEM...

find with char* variable doesnt work

I'd like to know why I have a memory error with this: The problem appears on char* value = aMap.find(keync)->second If I put manualy char* value = "key0" it works!!! using std::map; map <char*, char*> aMap; void search(const char* key) { const int LEN = strlen(key); char* keync = new char[LEN]; for (int i= 0; i < LEN; i...

Segmentation fault in std::map::insert(...)

hello, i've used search but i didn't find answer satisfying me... so.. this is chunk of code: //VoteContainer.h typedef uint32_t order_id_t; typedef int driver_id_t; class Vote { public: enum DriverVoteResponse {YES, NO, TIMEOUT}; struct DriverResponse { driver_id_t dri...