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

To which elements must the C++ requirement "Compare" apply?

To use a comparison operator for std::set (and many other data structures of course), it has to fulfil the Compare requirement, which is expressed as certain properties for keys a,b,c. (Crucially, in this case, equiv(a,b) and equiv(b,c) ⇒…
MadTux
  • 139
  • 1
  • 10
1
vote
2 answers

Using begin() and end() with a set in c++

I am trying use an iterator to go through a set and then do something with the members of that set(if there are any). The problem is that, normally this works, but sometimes, it compares the beginning and the end of an empty set and finds them not…
Kyle
  • 217
  • 2
  • 13
1
vote
3 answers

Moving through list elements

I need to move through list elements and add them to the set. However, while moving through list I need to skip elements that are already added to set. First element of list is added to set before moving through list. For example: {"Damir", "Ana",…
1
vote
1 answer

Vector of set insert elements

I'm trying to write a function which will return vector of set type string which represent members of teams. A group of names should be classified into teams for a game. Teams should be the same size, but this is not always possible unless n is…
1
vote
2 answers

std::set custom string comparison using boost::iequals

Following code works well without issues but wondering, if it is possible to rewrite custom comparison operator using boost::iequals , which compares without converting to upper. std::string copyToUpper(std::string s) { …
nsivakr
  • 1,565
  • 2
  • 25
  • 46
1
vote
1 answer

Is it possible to extract a struct containing fields that are unique/shared pointers from a set

so essentially I have a set of instances of struct A. I want to extract an instance, modify the fields. One of the fields is a unique ptr. I'm not that great at reading c++ errors, it looks like the field is deleted on extraction. I.e. the…
1
vote
1 answer

Surprising behaviour with an unordered_set of pairs

How can the unordered_set can hold both (0, 1) and (1, 0) if they have the same hash value? #include #include #include using namespace std; struct PairHash { template size_t…
andrey
  • 1,515
  • 5
  • 23
  • 39
1
vote
1 answer

Set of pointers to objects with custom comparator

I have a set of pointers and I want the set to be sorted in a specific order. I came up with this code and it works as expected: #include #include #include class Data { public: std::string name; int data; bool…
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
1
vote
2 answers

Template argument deduction/substitution failed with std::set

I've looked through a lot of posts that get the same error, but couldn't find one that applied to my problem, apologies if this is a duplicate regardless. Anyway my task is making a class called set_helper which makes std::sets a little easier to…
devor110
  • 121
  • 8
1
vote
1 answer

std:hash with access to private members of a class

I would like to hash a class that has two private members e.g.: foo.h class Foo { private: std::string a; std::string b; public: Foo (std::string a, std::string b); bool operator==(const Foo& other) const; …
Luke
  • 884
  • 8
  • 21
1
vote
0 answers

C++ std::set strange behavior?

I'm writing a party system for a game, and I'm getting some very strange behavior out of a std::set std::wstring that contains IP addresses for the party. The error I'm getting is in xtree, usually in clear, but I've also hit it in insert. It's a…
TDummy
  • 27
  • 3
1
vote
1 answer

std::set as a class member can't use function pointer as key_comp

I want to define a class member std::set with function pointer as key_comp, but compiler report "is not a type". bool compare(unsigned v1, unsigned v2) { ... } std::set GoodSet(compare); class BadSet{ public: …
wuyabiao
  • 13
  • 4
1
vote
2 answers

Finding the key with most values in map>

set myFunc (const map>& m) I want to return all the keys in a set of strings, that map the most values (several keys if number of mapped values is the same). My attempt was: set ret; auto max_e =…
smat
  • 11
  • 1
1
vote
1 answer

ordering in std::set of unique pointers

I have a std::set of unique pointers in a class like std::set> my_set{};, and I want to write a method that produces a sorted vector of the values pointed to by these unique pointers. Currently I've got: auto convert() ->…
user11508332
  • 537
  • 1
  • 11
  • 28
1
vote
1 answer

How to print a set in reverse order recursively in C++?

I've tried the following code to print an std::set in reverse order: #include #include #include #include #include #include #include #include #include using…