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

How to output a Map with keys of type string and the values are the set of strings

I"m writing a method called put() that is suppose to output a map with the correct values. My printing method works but my actual method doesn't make the map correctly. The keys are strings and the values of the map is a set of strings. My method…
CamWhis
  • 17
  • 6
0
votes
0 answers

Must a std::set store the tree's root?

A tree will be used as the internal data structure of std::set. The begin (and cbegin) methods of std::set have constant complexity, so std::set must have a private data member node pointer to the first element of the set; updated by calls which…
user2023370
  • 10,488
  • 6
  • 50
  • 83
0
votes
1 answer

C++ std::set metaprograming set of set of set ... nesting

I was trying to implement a n-tuple from scratch starting with the mathematical base ordered-pair where n-tuple (a,b,c) = ordered_pair(a,ordered_pair(b,c)) and ordered pair is a set representation ie. ordered_pair(a,b) = set{{a},{a,b}} here is the…
0
votes
1 answer

const references of set elements do not preserve information

I have two friend classes: class Node { private: unsigned id_; bool marked_; std::set neighbors_; friend class Graph; ...... public: bool operator == (const Node & other) const { return id_ == other.id(); } bool operator…
user123
  • 1
  • 2
0
votes
1 answer

Why does `std::set::erase(const key_type&)` return `size_type` instead of `bool`?

Because std::set doesn't insert() duplicates, it's assured to contain unique elements. When using the overload erase(const key_type&), its object would have contained maximum 1 element of that same value. Hence, it may return either 1 (if present)…
iammilind
  • 68,093
  • 33
  • 169
  • 336
0
votes
0 answers

C++ standard compliance of MSVC versions (regarding std::set::erase)

Is the implementation of the erase function of std::set on msvc v140 not conforming standard C++11? According to the standard (and as mentioned here) "the erase members shall invalidate only iterators and references to the erased elements."…
boojum
  • 181
  • 2
  • 15
0
votes
1 answer

how to typedef a specialized std::set template, instantiating with specific compare function

I found this example on another site: bool fncomp (Node lhs, Node rhs) {return lhs.val < rhs.val;} bool(*fn_pt)(Node,Node) = fncomp; std::set < Node, bool(*)(const Node &, const Node&) > example(ft_pt); but what I really want is a typedef so I can…
0
votes
1 answer

Why would dereferencing a pointer to an extracted node of std::set be undefined behaviour?

I did a lightning talk in my company on the new (C++17) splicing interface of the associative containers. I demonstrated std::set::extract and was then asked what would happen to iterators and pointers to the extracted element. They caught me on the…
Brandlingo
  • 2,817
  • 1
  • 22
  • 34
0
votes
1 answer

Change std::set to find item by T type

template class State { T state; double cost = 0; State *cameFrom = nullptr; I have this template class, and i want to create a std::set> the < operator of the class returns this.cost < other.cost the == operator of…
AD1234
  • 19
  • 1
  • 5
0
votes
3 answers

Are there any reasons not to extend std::set to add a subscript operator?

I'm using std::set to store unique instances of a class. std::set does not have an overloaded subscript operator so you can't do set[0] for example. I found a way to do it: auto myClass = *std::next(set.begin(), index); However, I found it…
0
votes
5 answers

Go through all triple of different values contained in a std::set?

Suppose I have a sorted vector without duplicated values. If I want to go through all the triples of different values, I do this: for(std::size_t i = 0; i < data.size(); ++i) for(std::size_t j = i+1; j < data.size(); ++j) for(std::size_t k =…
Caduchon
  • 4,574
  • 4
  • 26
  • 67
0
votes
2 answers

How do I Insert std::vector into a std::set which has a custom sort function

Note that the problem here has been solved and it had nothing to do with the insert but rather an uninitialized struct member variable! Hopefully this question and its answer might help another rookie avoid such a mistake. I want to insert a…
Algorithmic
  • 138
  • 12
0
votes
2 answers

Can replacing the std::allocator allow std::set to work with void* and separate copy/dealloc functions?

I'm fighting a problem with some legacy code trying to talk to modern systems. Specifically, C++11 versions of the STL (bonus points if your proposed solution works with C++03, negative points if solution only works with C++17, but I'm still…
srm
  • 3,062
  • 16
  • 30
0
votes
2 answers

std::set of shared_ptr's erasing leads to SIGABRT

I have std::set of shared pointers to objects of some type ( ints here are just for example ). What I need is to insert shared ptr's constructed from raw pointers. But when I'm trying to erase some of set elements ( again I have just a raw pointer…
Uroboros
  • 189
  • 2
  • 12
0
votes
1 answer

std::set Comparator that refer to external value

I have something like class ClassB { // .... private: static std::unordered_map activity; struct compare_values { bool operator()(const ClassA& l, const ClassA& r) const { return activity[l] <…
GiuMaz
  • 63
  • 1
  • 5