Questions tagged [stdset]

In C++, `std::set`s are a kind of associative container that stores unique elements, and in which the elements themselves are the keys.

294 questions
-2
votes
1 answer

Which is the fastest way to erase in set?

I read the cpp reference there are three ways to erase in std::set. void erase (iterator position) size_type erase (const value_type& val) void erase (iterator first, iterator last) Assuming I already know the iterator, which is faster, erasing…
jslee
  • 19
  • 1
-2
votes
1 answer

Seg fault with default allocation std::set

I am trying to learn STL allocators for void*. Here is my code #include #include class Test { public: std::set GetAllInformation() { return info_set_; } private: std::set info_set_; }; int main() { …
atulya
  • 535
  • 2
  • 8
  • 25
-2
votes
1 answer

In c++ code, set.erase(it) is halting execution, where it=set.begin() for a set of pairs, why is this happening?

Sorry for any inconvenience I am a beginner at C++ and was stuck with an empty set... Thank you for the helpful comments that helped me figure out what the problem was I wrote a C++ code for a question in which I need to use Dijkstra's shortest path…
-2
votes
1 answer

Why the C++ set subtraction could not be easier?

I am completely aware that set_difference can subtract two sets and I am aware that operators are syntactic sugars. But, I am wondering why the standard library designers do not provide such a functionality so subtraction becomes such easy? #include…
Kate
  • 31
  • 2
-2
votes
2 answers

How does this std::set initialization work?

I am having some trouble understanding how the std::set initialization works. I have the following code in a function: std::map my_map = { {16, 24}, {19, 29}, {15, 23}, {14, 22}, {13, 21}, {17, 28}, }; typedef…
-3
votes
1 answer

Task with inserting elements to list - tough a little

This is just a continuation of several past questions. My function should return std::vector> A group of names should be classified into teams for a game. Teams should be the same size, but this is not always possible unless n…
-3
votes
2 answers

std::map> here my_map[1] = std::set(); ---> what does this line serve

Below is my code, wanted to know what does the line my_map[1] = std::set(); serve? std::map> my_map; int main() { int i = 10; int *ptr = &i; my_map[1] = std::set(); my_map[1].insert(ptr); for…
user7809950
-3
votes
3 answers

Right way to remove an element in std::set

I have a graph class struct Graph { list vertices; }; int main() { Graph g; // fill out graph return 0; } I want to perform a Dijkstra-shortest-path-like algorithm. Step 1 would be creating a set out of all the nodes, which I…
ToniAz
  • 430
  • 1
  • 6
  • 24
-3
votes
2 answers

Find an element in std::set by a custom comparator

I created a class Route which I wanted to store in an std::set. A Route is indexed by an Id, so what I want is to be able to have an expression like class RouteTemplate { Route *RouteTemplate::getRoute(const char *pId); Route::ptr_set…
Devolus
  • 21,661
  • 13
  • 66
  • 113
1 2 3
19
20