stdmap Questions

2

The "four basic kinds" of C++ sequence containers (vector, forward_list, list, and deque) all have an assign method. For example, std::vector has (quoting cppreference.com): void as...
Lyric asked 4/8, 2024 at 19:51

2

Solved

I have two std::map<> objects a and b and would like to move (extract + insert) some elements (nodes) from one map to the other based on some predicate p. for (auto i = a.begin(); i != a.end...
Nonsense asked 13/11, 2019 at 14:24

1

Solved

I just noticed that std::map and std::set have the member function equal_range() returning an iterator range of values for a certain key. How does this make sense when std::map and std::set a...
Garwin asked 1/5, 2024 at 8:36

3

Solved

Language: C++ One thing I can do is allocate a vector of size n and store all data and then sort it using sort(begin(),end()). Else, I can keep putting the data in a map or set which are ordered i...
Revitalize asked 6/5, 2018 at 10:49

3

Solved

If there is a std::map<std::pair<std::string, std::string>, some_type> what is the best way to find its values? I guess the most obvious one is to do something like this: map.find(std::...
Obscuration asked 14/1, 2024 at 0:48

25

Solved

This is one of the possible ways I come out: struct RetrieveKey { template <typename T> typename T::first_type operator()(T keyValuePair) const { return keyValuePair.first; } }; map<...
Hepburn asked 21/9, 2008 at 3:23

5

Solved

I tried to use the operator[] access the element in a const map, but this method failed. I also tried to use at() to do the same thing. It worked this time. However, I could not find any reference ...
Volkan asked 27/2, 2011 at 17:17

5

Solved

I'm trying to create a map inside a map: typedef map<float,mytype> inner_map; typedef map<float,inner_map> outer_map; Will I be able to put something inside inner map, or does iterat...
Darwen asked 21/3, 2011 at 12:15

5

I'm trying to use a std::string as a key in a std::map however, i'm unable to find() correctly. My code is somewhat complicated and large so this is a small program that demonstrates the problem I'...
Facies asked 4/12, 2011 at 10:54

3

Solved

I have a recurrent pattern with the use of std::map. I want to retrieve the value only when the key is present, otherwise I don't want to insert element. Currently I'm using count(key) or find(key...
Microgamete asked 10/10, 2013 at 8:30

1

Solved

The common advice is to prefer using std::map::try_emplace in preference to std::map::emplace in almost every instance. I wrote a simple test to trace object creation/copying/moving/destruction whe...
Rip asked 14/6, 2023 at 21:8

6

Solved

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 nt...
Alex asked 27/11, 2009 at 14:57

15

Solved

I'm trying to check if a given key is in a map and somewhat can't do it: typedef map<string,string>::iterator mi; map<string, string> m; m.insert(make_pair("f","++--")); pair<mi,mi&...
Ridgepole asked 21/12, 2009 at 12:55

6

Solved

I want to define something like Map<int, char[5] > myMap; The above declaration is accepted by c++ compiler and no error is thrown but when I do something like this int main() { char arr...
Mcquillin asked 16/7, 2012 at 17:28

16

Solved

Is there a way to specify the default value std::map's operator[] returns when an key does not exist?
Gravimetric asked 25/2, 2010 at 11:57

1

Solved

I noticed that the use of std::map::reverse_iterator in the below example doesn't work with C++20 but works with C++17 in all compilers. Demo Demo MSVC #include <map> class C; //incompl...
Snider asked 13/8, 2022 at 10:52

5

Solved

I want to inherit from std::map, but as far as I know std::map hasn't any virtual destructor. Is it therefore possible to call std::map's destructor explicitly in my destructor to ensure proper o...
Shiksa asked 7/5, 2012 at 6:47

10

Solved

I am trying to figure out why the following code is not working, and I am assuming it is an issue with using char* as the key type, however I am not sure how I can resolve it or why it is occuring....
Bondman asked 11/11, 2010 at 18:4

6

Solved

I have the following shared_ptr to a map: std::shared_ptr<std::map<double, std::string>> and I would like to initialise it using braced-init. Is it possible? I've tried: std::strin...
Flagging asked 6/4, 2016 at 8:32

8

Solved

Basically I want MyClass that holds a Hashmap that maps Field name(string) to ANY type of Value.. For this purpose I wrote a separate MyField class that holds the type & value information.. T...
Foti asked 11/7, 2014 at 16:18

8

Solved

I want to iterate through each element in the map<string, int> without knowing any of its string-int values or keys. What I have so far: void output(map<string, int> table) { map<...
Discophile asked 9/10, 2014 at 15:12

13

I'm pretty sure I already saw this question somewhere (comp.lang.c++? Google doesn't seem to find it there either), but a quick search here doesn't seem to find it, so here it is: Why does std::map...
Pharmacognosy asked 28/10, 2009 at 19:30

7

Solved

What I mean is - we know that the std::map's elements are sorted according to the keys. So, let's say the keys are integers. If I iterate from std::map::begin() to std::map::end() using a for, does...
Vesuvian asked 4/10, 2011 at 13:35

8

I'm wondering why I can't use STL maps with user-defined classes. When I compile the code below, I get the following cryptic error message. What does it mean? Also, why is it only happening with us...
Grantinaid asked 9/7, 2009 at 7:42

5

Solved

I am looking for the highest key value (a defined by the comparison operator) of a std::map. Is this guaranteed to be map.rbegin()->first ? (I am a bit shaky on reverse iterators, and how...
Brinton asked 14/11, 2008 at 10:31

© 2022 - 2025 — McMap. All rights reserved.