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

std::set using class pointers. How to control insert

I have been google all over the place and am unable to find a working example for how to use std::set and control the insert order. I found comments for my type of structure but I get a compile error. I am trying to sort on myMaskName so I get …
user3416126
  • 148
  • 11
0
votes
0 answers

Is it somehow possible to pass a set constructor a lambda function with a non-empty capture list as the set's compare function?

I have a struct: struct some_struct { int i; char c; }; Now I want to put it in a std::set using a custom compare function: set s_s( [](some_struct* s1, some_struct* s2)->bool…
user4385532
0
votes
2 answers

required from 'std::pair, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique

I'm getting a compilation error, required from 'std::pair, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = Solution::EnhancedNode* const&; _Key =…
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
0
votes
2 answers

std::set doesn't detect duplicate custom objects

I have a map for keeping the team name and players of the team std:pair > and a set of pointers to players to keep the players sorted in descending order by wins. And there's the catch - one player can…
0
votes
0 answers

Can't insert elements in a set of sets

I have a structure with some properties and a set. I have multiple instances of those structs inside another set. When I try to add something to the set inside the struct: test2.cpp: In function ‘int main()’: test2.cpp:42:22: error: no matching…
Joaquim Ferrer
  • 603
  • 6
  • 23
0
votes
2 answers

std::set

I've tried to use set to keep some configurations in a trie lately. I've found a doubt on the comparator, for instance : #include #include using namespace std; struct Node{ int position; int…
Ruan Kotovich
  • 579
  • 1
  • 4
  • 11
0
votes
3 answers

How to remove items from position i in std::set?

std::set tmp_{30, 40}; int i=0; while(tmp_[i]==40) { i++; } tmp_erase(i); How do I remove an element at position i?I cannot use erase because i is not std::set::iteretor
M.Devan
  • 169
  • 2
  • 13
0
votes
2 answers

C++ std::set with a custom lower_bound

How would I perform a find() or lower_bound() function on a std::set using a comparator function that is independent of its key such that it still runs in O(log N) time? Suppose I define a data type foo with two variables x and y and have a…
0
votes
4 answers

Bug in C++ Set?

When I tried this part of the code: int x=*(s.rbegin()); while(!s.empty()&&0
0
votes
1 answer

Return an iterator to boost multiintex container as a std::set<>::iterator

The documentation for Boost multiindex containers seem to indicate that I can use it as a set after declaring an index to iterate over. So I was wondering if it is possible to hide the boost implementation and return an iterator masqueraded as an…
xcorat
  • 1,434
  • 2
  • 17
  • 34
0
votes
2 answers

Base class of sorted containers in C++

Does C++ have a common base class for sorted containers like std::set or std:map? Background: I want to implement a generic function which deletes all elements in a container which are not found in another container. As a precondition I want to…
user1056903
  • 921
  • 9
  • 26
0
votes
0 answers

Remove a shared_ptr from std::set without using boost library in order to delete an edge from a graph's edges_

I have a std::set declared as the following: std::set> edges_; I want to remove a shared_ptr, effectively one of the edges stored in edges_, from the set. It does go into the if loop where it prints that it has found the edge,…
iteong
  • 715
  • 3
  • 10
  • 26
0
votes
0 answers

Implement a custom compare class for std::set (using std::shared_ptrs) that compares edge objects of a directed weighted graph

I'm trying to delete an edge from edges_, which is stored in a Graph class Node struct as a std::set using std::shared_ptr: template class Graph { private: struct Node; struct Edge; struct…
iteong
  • 715
  • 3
  • 10
  • 26
0
votes
1 answer

Deleting an edge from edges_ that is declared as std::set> edges_;

I'm new to std::shared_ptr and std::set. For the following code, I want to know how I can delete the edge from edges_. edges_ is declared as std::set> edges_; and I want to delete the edge referenced by the shared pointer…
iteong
  • 715
  • 3
  • 10
  • 26
0
votes
1 answer

Deleting edges for a node in a directed weighted graph that uses smart pointers

I'm pretty new to shared pointers and am trying to delete a node from the graph. When I delete a node, the incoming and outgoing edges stored in that node will be deleted. However, I also need to delete the outgoing and incoming edges (which is the…
iteong
  • 715
  • 3
  • 10
  • 26