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
2
votes
2 answers
Can I make a constexpr object of std::set?
I need a const object of std::set, which will be used in many other cpp files.
Since that the initializing-order of each parts of the app is undefined, I may get a empty set when I initialize other const objects with this std::set obj.
So, I want…

Leon
- 1,489
- 1
- 12
- 31
2
votes
3 answers
How to sort std::set according to the second element?
Given n points in a two-dimensional space, sort all the points in ascending order.
(x1,y1) > (x2,y2) if and only if (x1>x2) or (x1==x2 && y1
user11376749
2
votes
3 answers
Error: passing x as 'this' argument of x discards qualifiers
I'm writing a HeartbeatManager for my application (in visual studio). The data of 1 heartbeat is stored in a Heart object. The Heart objects are stored in an std::set. For this reason, I am implementing the operator=, operator< and operator>…

Cpt. Pineapple
- 139
- 2
- 11
2
votes
0 answers
error: no matching constructor for initialization of 'std::__1::pair
So I've been going at this for the past few days and can't seem to get my head around it any and all help is so very much appreciated and grateful of.
Thank you so very much.
Error Code:
/usr/local/include/boost/assign/list_of.hpp:164:20: error:…

vivianredwards
- 29
- 1
2
votes
1 answer
Reverse iterator is being advanced by std::set::erase
I am trying to erase the element that I just traversed into. I initially forgot to store the return value of s1.erase(... inside the for loop to ultimately set the condition to exit the loop. With the way the code is right now, I expected the loop…

MoD
- 33
- 5
2
votes
1 answer
C++ set with a comparator for sort and another for uniqueness
Edge is a class with 3 fields: weight, from_vertex, to_vertex. I want to create a set containing all unique edges in a graph. (If from_vertex and to_vertex are swapped -and weights are equal-, it is still the same edge.) Also, I want this set be…

Den
- 37
- 5
2
votes
3 answers
Error with custom struct: "VS 2015 error C2678: binary '<': no operator found which takes a left-hand operand of type 'const Node'"
I am attempting to create an implementation of the A* algorithm on a 2D grid and have arrived stuck at the point where I am needing to create a set of a node's neighbours. Below are the structs I am using.
// Holds values for x and y locations on…
user4415680
2
votes
1 answer
Ordering a set of pairs in decending order by the first value and then alphabetically by the second value
I have a set of pairs of integers and sets, e.g:
items = {(2,{"A", "B", "C"}),(3,{"C"}),...}
I have it set up this way because stl sets can be easily ordered by writing a comparator for the declaration, I do not know how to write such a function to…

Daryl Drake
- 29
- 1
- 5
2
votes
1 answer
Count distinct elements from a concurrently read stream
I have multiple listeners threads reading a stream of messages (Kafka). Each message has an identifier. The consumers/stream guarantees at-least once consumption. At most of the time, the stream would provide the message exactly once. The count of…

Mukul Gupta
- 2,310
- 3
- 24
- 39
2
votes
1 answer
Make std::set to use conversion operator when compare elements
Currently I use std::map to save key/value pairs:
#include

Tomilov Anatoliy
- 15,657
- 10
- 64
- 169
2
votes
0 answers
why is std::set `lower_bound` a `const_iterator` in this c++ example
I don't understand why this doesn't compile.
#include
#include
struct Foo
{
struct Rec
{
std::string _s;
Rec(const std::string& s) : _s(s) {}
bool operator==(const Rec& r) const { return _s ==…

jkj yuio
- 2,543
- 5
- 32
- 49
2
votes
2 answers
How to initialize a map from a set
I want to set the keys of a std::map using the elements of a std::set (or a std::vector).
Something like the following...
std::set keys = { 3,4,6 };
std::map results(keys); // syntax error
Can this be done without explicitly…

Brent Bradburn
- 51,587
- 17
- 154
- 173
2
votes
0 answers
std multiset insert and keep length fixed
I am interested in inserting elements in a std::multiset but I would like to keep the set fixed length. Every time an element is inserted, the last element will be removed. I came up with the following solution
int main(){
…

JVn
- 21
- 2
2
votes
1 answer
Std::map \ std::set contain duplicate keys
I have an issue and though I understand, that is kind of a stupid question to ask, but I failed to find a solution on my own.
So, I'm trying to accumulate a container with unique values of a structure I have.
struct Symbol {
D2D1_RECT_F bbox;
…

Aleksandr Kurinnoi
- 201
- 1
- 9
2
votes
2 answers
Faster lookup than std::set
I need a faster membership lookup for some legacy packet processing code which needs to identify if a packet with a particular ID is in a particular list.
The list is only updated every few seconds while the packet matching happens very very often,…

Danny
- 2,482
- 3
- 34
- 48