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
0
votes
2 answers

std::set weird < overload error

So, I've got this code: #include #include class Section; class Config; class SettingBase { public: virtual ~SettingBase() { } }; template class Setting : private SettingBase { friend class Section; public: …
Misguided
  • 1,302
  • 1
  • 14
  • 22
0
votes
3 answers

set list in c++

I've created a set list in c++ and fullfilled with elements std::set myUnits; for(std::set::iterator i = myUnits.begin(); i != myUnits.end(); i++) { if() {} } So i want in if to check every element of the setlist, what…
snake plissken
  • 2,649
  • 10
  • 43
  • 64
0
votes
1 answer

How do I let the user iterate in reverse (one by one) through this map / set container?

I have asked this question again (updated) at the suggestion of one of the StackOverflow members (see comment to this question: Traversing a bidirectional iterator back to the first element). I have these aliases: using SuggestedPublishersSet =…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
3 answers

Traversing a bidirectional iterator back to the first element

There is something that I can't quite get my head around with bidirectional iterators. Going forward through the collection is ok: auto it = set.begin(); while (it != set.end()) { // Do something it++; } end() is the element after the last…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
2 answers

Is passing a pair of long long in set find safe?

I have the following code: std::set> my_set; long long x = (some value); long long y = (some value); // should be true if x or y exceed the limits of int bool z = my_set.find({x, y}) == my_set.end(); It works without any…
MangoPizza
  • 269
  • 2
  • 8
0
votes
0 answers

How to define operator < for std::set with pointer

I use std::set and I overloaded the operator <(const CTest&) ok it is working, but I am trying to do the same with pointers: std::set operator <( CTest* ) it is not working, when inserting objects to the set it is not even going…
0
votes
1 answer

Container that can iterate in order, access specific elements, and remove elements

I am currently using a std::vector vec of size nto store the integers from 0 to n-1 in any order. Suppose that the vec is given by the following: std::vector vec = {4, 1, 2, 0, 3}; I need to iterate over vec in order, i.e. 4 -> 1 -> 2 ->…
s1624210
  • 627
  • 4
  • 11
0
votes
0 answers

making a set/map comparator with find by equivalence

What are the requirements to ensure that type equivalence can be used in the find function of a sorted container? Specifically how does mixed type comparison work. Setup Say I've got a struct, comparator, and set struct Wrapper{int…
Sir Demios
  • 83
  • 11
0
votes
2 answers

How can I efficiently search for multiple adjacent elements in a std::set?

I have a set containing a sortable data type. I need to be able to search to find all elements that lie between two unknown points within this set. For the sake of simplicity I'll use some pseudocode to describe this. set = { (a, 0), (a, 3), …
Miguel Guthridge
  • 1,444
  • 10
  • 27
0
votes
0 answers

How can I efficiently find elements in a std::set of std::shared_ptrs?

I have a std::set of std::shared_ptrs. I want to be able to use a builtin method such as find in order to efficiently search for elements within this set. However since shared pointers to equal objects aren't equal, doing so doesn't work. #include…
Miguel Guthridge
  • 1,444
  • 10
  • 27
0
votes
2 answers

std::set: Using iterator causes memory violation exception

I have below code. The code doesn't work in Visual Studio. But in another compiler, such as onlinegdb.com, it works fine. And output " #include #include using namespace std; int main() { set ms{1,2,3,4,5}; set…
Triho
  • 29
  • 1
  • 5
0
votes
3 answers

Accessing an std::set via a dereferenced iterator

Consider: #include #include void printset(std::set& Set) { for (std::set::iterator siter = Set.begin(); siter != Set.end(); ++siter) { int val = *siter; printf("%d ", val); } } void…
Tryer
  • 3,580
  • 1
  • 26
  • 49
0
votes
2 answers

double free detected in tcache 2 when calling erase() on std::set

i was writing a simple code for testing purposes. if i declare the node1 first, there's no problem but when i declare the node2 first, the code give me free(): double free detected in tcache2. could someone please explain the reason for this double…
faza akbar
  • 11
  • 2
0
votes
2 answers

C++ set with customized comparator crashes on insert

STL set can have customized comparator. It can be implemented in several ways, such as define an operator(), use decltype on lambda, etc. I was trying to use a static method of a class and encountered a weird crash. The crash can be demonstrated by…
0
votes
1 answer

std::set iterating over all pairs

Consider code snippet 1: #include #include int main() { std::set intset = {1, 2, 3, 4, 5, 6}; for(std::set::iterator it1 = intset.begin(); it1 != intset.end(); it1++) for(std::set::iterator it2 = it1 + 1;…
Tryer
  • 3,580
  • 1
  • 26
  • 49