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

What is the best way to change a set during iterations?

Given std::set , what is the best way to change the set during time-iteration? For example: std::set s; // T is a some type (it's not important for the question). // insertions to s for (std::set::iterator it = s.begin(); it != s.end();…
Software_t
  • 576
  • 1
  • 4
  • 13
1
vote
2 answers

How to add distinct pairs into a set?

I am trying to insert a few pairs of int into a set, these pairs don't have any order; that is, (1,2) = (2,1). So simply I do as follows, typedef pair pairs; set Set; pair myPair; // adding…
Sarah
  • 133
  • 11
1
vote
2 answers

Using a Constant Character Pointer in a std::set Container: Memory Consumption

I'm currently working on a device with very little memory (4MB) and I have a component of my program that requires an std::set. I would like to migrate this set from using std::string to using const char pointers but I was wondering how memory is…
Wheatevo
  • 643
  • 1
  • 5
  • 10
1
vote
2 answers

Why doesn't type deduction work for my set intersection and set difference invocations?

I am trying to write a small algorithm that finds the common and unique parts of two sets and I want to write it in a generic fashion so I have this little example: #include "boost/tuple/tuple.hpp" #include template
Bob Fang
  • 6,963
  • 10
  • 39
  • 72
1
vote
1 answer

inspect C++ std::set in VSCode with LLDB

This is a VSCode specific question. Asking here since the VSCode repo points to asking question on SO. I'm using VSCode on Mac OS, with LLDB. I'm trying to figure out how to inspect a std::set. I can't find any doc on this; I found some ways to do…
MrE
  • 19,584
  • 12
  • 87
  • 105
1
vote
3 answers

Fast union building of multiple vectors in C++

I’m searching for a fast way to build a union of multiple vectors in C++. More specifically: I have a collection of vectors (usually 15-20 vectors with several thousand unsigned integers; always sorted and unique so they could also be an std::set).…
Flauer
  • 11
  • 3
1
vote
3 answers

how to print std::set of std::maps

Here is the map with a string key and a structure value 1. Firstly I am creating a map of integer and a structure as value std::map; and then I am adding all these map objects to a set std::set> and I…
LearningCpp
  • 972
  • 12
  • 29
1
vote
2 answers

Why can't I call a non-const member function on an element in an std::set?

I hve the next code: set temp_items; set < Item >::iterator it; temp_items = user->second.get_items(); for (it = temp_items.begin(); it != temp_items.end(); it++) { if (counter == (choice - 1)) { it->get_count(); } } The…
dfsfg sfg
  • 77
  • 1
  • 9
1
vote
1 answer

Update std::set to keep only the smallest values

For some algorithm I have to call a function f on all permutations of the n-element set of integers ranging from 1 to n. Finally, I am interested in the 100 permutations yielding the smallest f-value. The best solution I was able to work out was…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
1
vote
1 answer

Weird behaviour of std::multiset and upper and lower bounds

I'm looking for code which counts the different occurences of elements inside a std::multiset. I have following code #include #include #include #include struct test { std::pair p; …
user1587451
  • 978
  • 3
  • 15
  • 30
1
vote
2 answers

std::set of std::string inequality implementation

Since std::set is implemented as a binary tree, how does it compare std::string for inequality? Does it look like a < b && b < a? Is it using the length of the string directly or is it hashing it somehow? Does it at all guarantee uniqueness of…
Lev
  • 1,698
  • 3
  • 18
  • 26
1
vote
2 answers

Finding elements in std::set

Given that I have a std::set, how do I find out if one element of the set is before the other. For example, something like this - bool before(const std::set &s, const int first, const int second) const { auto it_first = s.find(first); auto…
ssb
  • 7,422
  • 10
  • 36
  • 61
1
vote
1 answer

std::set with unconsistent operator<

I'm writing a C++ algorithm to solve a board game. The solution is based on the following: enqueue initial board while queue not empty: dequeue a board if board is solved: print solution else: for each possible board that…
c.bear
  • 1,197
  • 8
  • 21
1
vote
1 answer

Does std::set.find(element) use the == operator from the class to compare the elements?

Say I have std::set set; class classtype { bool operator==(const classtype& ct) { //.. } }; //.. std::set::iterator it = set.find(element); Find does use the == operator from the class correct? Also my…
myelf
  • 43
  • 5
1
vote
3 answers

Lookup objects by name on std::set

I need to store some objects in a std:set (or any other kind of lookup table) and search those by name. For example, suppose I have a class like (pseudo code): class Person { std::string mName; int mAge; ... //etc }; I would like to…
bcsanches
  • 2,362
  • 21
  • 32