In C++, `std::set`s are a kind of associative container that stores unique elements, and in which the elements themselves are the keys.
Questions tagged [stdset]
294 questions
0
votes
1 answer
Shared temp file management
My application starts several similar processes. First one creates a "global" temp file that they all red/write. When last process is destroyed, this file needs to be deleted.
Later more processes may be spun up and this file should be…

L8Cod3r
- 60
- 6
0
votes
1 answer
std::set custom compare function for double values. insert() does not work
I created a set via
bool(*fn_pt)(const double&, const double&) = comp_double;
std::set values(fn_pt);
where my comp_double function is given by
bool comp_double (const double& p1, const double&…

Simon
- 325
- 1
- 6
0
votes
1 answer
Templating ordered vector and std::set
So I want an interface that stores some numbers in order and efficiently perform some operations on them. In practise, a sorted vector performs very well for small sizes, but for theoretical performance and performance on larger instances, I need…

Henk
- 826
- 3
- 14
0
votes
1 answer
How can I get the strictly lower value than upper bound in a std::set?
Say I have a set
s={1 5 10}
Now if I run a loop for [0,2] and everytime check for the strictly lower than upper bound of the set than how can I handle lower value than s.begin() ?See the code for further clarification-
sets;
…

Perdente
- 75
- 2
- 11
0
votes
3 answers
spurious "containment" in std::set of pointers
A set of pointers is reporting that it "contains" a brand-new object, even though this object was just created, and has a memory address which differs from those already in the set.
#include
#include
#include
using…

BD107
- 159
- 8
0
votes
1 answer
Why does std::set::insert() call operator<() with bad parameter
I need help to understand why std::set::insert(T) is calling operator<(const T&, const T&) with an invalid reference as its second parameter, creating a segfault upon my first insertion.
Here is the class whose objects I want to insert in a…

scozy
- 2,511
- 17
- 34
0
votes
1 answer
std::set::erase unexpectedly erases 3 elements
Before the last erase, the elements in the s1 and s2 are the same.
The last erase to the s1 erases 1 element in the set s1. It is correct.
The last erase to the s2 erases 3 elements in the set s2. It is unexpected.
#include
#include…

Christophe
- 195
- 2
- 9
0
votes
1 answer
How to get the first element in a std::set of pointers, where the pointer points to a specific value?
Say you have a C++ std::set of unique pointers e.g.
auto my_set = std::set>
{
std::make_unique("monkey"),
std::make_unique("banana"),
std::make_unique("orange")…

user11508332
- 537
- 1
- 11
- 28
0
votes
1 answer
Is there any way to sort set of pair of int and pair by greater int and smaller pair in c++?
I have a set > ms that I want to sort it by greater int and smaller pair. For example, if these are the data in my set:
<10, pair<100, 120> >
<20, pair<45, 60> >
<20, pair<50, 10> >
I want it to be this after sorting…

Parisa Mousavi
- 52
- 1
- 11
0
votes
2 answers
set::find finds an element that does not exist
I have the following Edgeclass:
class Edge {
public:
int src, dest;
bool operator== (const Edge &edge) const {
return ((src == edge.src) && (dest == edge.dest)) || ((src == edge.dest) && (dest == edge.src));
}
bool operator<(const Edge& edge)…

Gökberk Şahin
- 45
- 2
- 8
0
votes
1 answer
cannot reset std::shared_ptr object inside std::set<>... why?
In the below c++ calling reset() inside list, vector, map there is neither error nor warning.
however when I try to do it in set I get error.
error message is [ No matching member function for call to 'reset' ]
why this happened??? Can someone share…

Kiseong Yoo
- 97
- 1
- 7
0
votes
2 answers
Why does std::set.erase(first, last) impact the container from which (first, last) were taken?
I will preface that I'm fairly new to C++ in general. Recently, I ran into some perplexing behavior from the std::set.erase() method, which I have isolated into the following code. This code sample crashes with a segmentation fault when it hits the…

trevorKirkby
- 1,886
- 20
- 47
0
votes
2 answers
Template function to return containers of unrelated types
I have several containers of unrelated types. I would like to write a templated function to process input values and insert them into the corresponding containers. This is my best try so far:
#include
#include
struct A {
// Must…

Walter Nissen
- 16,451
- 4
- 26
- 27
0
votes
3 answers
Why/Are unordered_map and unordered_set slower?
I was solving a simple problem of finding unique elements in an array. I used a std::unordered_map to count unique elements but it gave Time Limit Exceeded in one test case. Then I used a std::unordered_set with the same result.
PS: I used…

Devansh Messon
- 33
- 2
- 8
0
votes
0 answers
Storing the iterator of a set to user-defined type in a std::deque in C++
I have a std::set of user-defined type which contains sorted-values based on some criteria[overloaded < operator]. I want to store the iterator from this set into a std::deque which I can use later to update/delete entries from set.
Here's what I…

Abhi Sharma
- 41
- 9