Skip to main content
1 vote
2 answers
136 views

Are the map/multimap iterators interchangeable?

In the code below I'm defining a map and a multimap. Then I'm defining four iterators assigning them values from these containers: std::map<int, double> m; std::multimap<int, double> mm; ...
Dmitry Kuzminov's user avatar
2 votes
2 answers
131 views

Structured binding for std::views::enumerate of std::map [duplicate]

I'm trying to do something like this: const std::map<char, int> histogram{ {'A', 2}, {'D', 1}, {'M', 1}, }; for (const auto& [index, key, value] : std::views::enumerate(...
Adam Badura's user avatar
  • 5,533
0 votes
1 answer
174 views

Removing an element from a map of vectors

std::map<unsigned long, std::vector<Foo*> > fKeys = myObject->GetFoo(); for (auto it = fKeys.begin(); it != fKeys.end() && !found; ++it) for (auto it1 = 0; it1 < (*it)....
Igor's user avatar
  • 6,453
0 votes
1 answer
149 views

How to give a hint to std::map::lower_bound?

I want to give hints to std::map::lower_bound. Why isn't it even allowed? Suppose we need to implement something like: static constexpr int TOTAL_SIZE = 1'000'000; std::map<int, std::string> map{...
Capy Bara's user avatar
3 votes
1 answer
116 views

Maximum size of static local container in C++

To avoid reporting too many errors repeatedly, I use the std::map container to cache the error code and corresponding channel number, on the other hand, for the same error occurred on the same channel,...
Keelung's user avatar
  • 429
2 votes
3 answers
218 views

Is std::map::operator[] thread-safe if it doesn't insert?

We insert some keys into a std::map in a single thread. Then in multiple threads, we get values using operator[] for some keys; these keys are guaranteed to have been inserted in the first step. (No ...
Xellos's user avatar
  • 742
2 votes
2 answers
84 views

How to use std::map::emplace to add a default constructed value when it is not movable

This compiles: #include <map> struct S { int val = 0; S() = default; S(S&&) = default; }; int main() { std::map<int, S> values; values.emplace(42, S{}); } ...
Oersted's user avatar
  • 3,479
2 votes
1 answer
108 views

C++17 std:map w/allocator gives compile error C2338 (VS 2022)

I use std::map with a simple compare function and an allocator. Under C++17 with a map pair of std::pair<type1, type2>, I have learned that the allocator return type is required to be std::pair&...
Ted Ford's user avatar
1 vote
1 answer
146 views

Mutable static variables in consteval contxt

I'm trying to implement a consteval lambda to compute the nth Fibonacci number. I want to create a result cache in the lambda which I can use if the result is already cached. Here's what I have up ...
Setu's user avatar
  • 1,086
-2 votes
1 answer
49 views

How to get reference to std::map from own class inherited from (protected) map [duplicate]

I have my own class inherited from std::map, with overtyping operator to std::map. And if I want to use it, something is wrong (conversion to unaccessible base class): class CMyMap : protected map&...
Michal Hadraba's user avatar
4 votes
1 answer
97 views

C++ std::map<std::string, AnyType> find a range of partially matching strings

I have a std::map<std::string, AnyType> with following item keys: /abc/def/ghi /abc/def/jkl /abc/def/mno /abc/pqr/ghi /abc/pqr/stw /abc/xyz/ghi /abc/xyz/jkl /abc/xyz/mno /abc/zzz/mno is there ...
no one special's user avatar
2 votes
1 answer
94 views

How to pick top k elements from std::map

I have a std::map with uint32_t as the key type and a custom value type. I want to pick out the top k key value pairs from this map based on the members of the value type. To do this, I'm first ...
Setu's user avatar
  • 1,086
2 votes
3 answers
154 views

How to move elements from std::map to std::vector

I have a std::map which contains a bunch of key value pairs. I want move these elements into a std::vector. I tried using std::transform from <algorithm> to do this, but it doesn't work. Here's ...
Setu's user avatar
  • 1,086
3 votes
3 answers
163 views

How do I initialize an inplace key value pair in std::map

I want to insert key value pairs into a std::map with uint32_t as the key type and a custom type for values. Based on the documentation of std::map, I wrote the following code: #include <cstdint>...
Setu's user avatar
  • 1,086
-9 votes
2 answers
111 views

std::map comparison behave weirdly [closed]

Recently, I've been working on a Leetcode problem. In this problem, I tried to create a std::map<string, int> and instead of comparing the string based on alphabetical order, I want to compare ...
kudos3110's user avatar

15 30 50 per page
1
2 3 4 5
101