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
1
vote
1 answer

Class with std::unordered_set of pointers of same class

I am trying to create a class that has contains an std::unordered_set of pointers to the same class but am unable to find a way to prepare the hash function before declaring the class. struct hash { inline std::size_t operator()(Vertex const * &…
1
vote
1 answer

set::find() not working with user define data type

When I am searching for a key which is not present in my set then find() instead of returning iterator to end is returning an iterator to an another object which is not equal to key but present in set. I have no idea whats going wrong. CODE class…
Ashutosh Aswal
  • 494
  • 3
  • 12
1
vote
2 answers

Unordered selection implementation based on std::set ends up having duplicates

Trying to implement a combination of 4 objects taken 2 at a time without taking into account the arrangement (such must be considered duplicates: so that order is not important) of objects with std::set container: struct Combination { int m; …
Slaus
  • 2,086
  • 4
  • 26
  • 41
1
vote
2 answers

How do I delete elements from an std::set that is stored inside a std::map?

I have the following data structure stored in a class. class MyClass { private: std::map> myMap; public: void remove(std::string id); //trying to remove items from sets inside myMap } There is then a method…
Jane Wayne
  • 8,205
  • 17
  • 75
  • 120
1
vote
0 answers

How to edit an element in std::set without using 'mutable' or 'const_cast', and without erasing and inserting again?

Suppose I have a struct called "ClientInfo", This struct holds some information about some clinet. And suppose each client has a constant ID and some other information like 'Address' or 'Balance' that can be changed. If I want to store clients…
StackExchange123
  • 1,871
  • 9
  • 24
1
vote
3 answers

Modifying the value of a user defined type in `std::set`

Consider the case where I have a user defined type with say a id() member function which returns a unique std::string. I want a container of this objects, where the id() uniquely identifies the elements, but I want to "use" the objects to do other…
111111
  • 15,686
  • 6
  • 47
  • 62
1
vote
3 answers

How to use lower_bound/upper_bound to get index number from std::set?

I am trying to use Binary search function provided by STL which requires a vector to be sorted first. So that's why I am trying to directly use Set so i don't have to sort first. But when used set in the following way, ` #include…
jongla
  • 113
  • 1
  • 5
1
vote
2 answers

Error C2676: std::set::const_iterator doesn't have operator+ function?

std::set s = { 1,2,3,4,5 }; std::set s2(s.begin(), s.begin() + 2); I want to assgin several values of s into s2. But got below compile error: Error C2676 binary '+': …
Zhang
  • 3,030
  • 2
  • 14
  • 31
1
vote
3 answers

How to properly free a set of pointers?

If I have a container like a std::set of pointers to dynamic objects then how can I free its elements? int main() { // new scope { int x = 10; std::set spi; spi.insert(new int(1));// elem is a dynamic object…
Maestro
  • 2,512
  • 9
  • 24
1
vote
2 answers

Which part of the language forbids changing elements of an std::set

An std::set is a sorted associative container that offers fast lookup of it's elements. Keys are inserted in a sorted fashion and keys can't be modified once inserted to preserve that order. Consider the following demonstration that constructs an…
François Andrieux
  • 28,148
  • 6
  • 56
  • 87
1
vote
2 answers

Why do standard associative ordered containers allow `const char*` as their key?

As far as I know we should never compare two const character strings using relational operators <>... because the fact that it compares the addresses rather than the values: const char* sz1 = "Hello"; const char* sz2 = "hello"; if(sz1 < sz2);// not…
Itachi Uchiwa
  • 3,044
  • 12
  • 26
1
vote
2 answers

How does this line the following program contains the iterator to specific element?

I found the following program on cplusplus.com. // set::insert #include #include int main (){ std::set myset; std::set::iterator it; std::pair::iterator, bool> ret; // set some initial…
Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
1
vote
1 answer

Is that a bug in Qt Creator analizer

While working with some code I experienced QT Creator performance degradation. Actually it launches a thread that occupies 100% CPU in an infinite loop: even closing the IDE process without killing it becomes impossible. This is fully reproducible…
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
1
vote
1 answer

How to access map of set of pairs elements?

#include #include #include #include int main() { std::map>>map1; for(int i = 0; i != 3; ++i) map1[i].insert({i+1,i+2}); for(auto i : map1){ …
Aditya Ishan
  • 507
  • 7
  • 21
1
vote
3 answers

Iterating over std::set, how to keep track which ones to remove?

I need to loop over some objects of class T. They are stored in an std::set> tees. The main purpose of the loop's body is to use the objects, but by doing that I will also find out when some of the objects are no longer needed and…
T. Herzke
  • 627
  • 4
  • 12