stdset Questions

1

Solved

I just noticed that std::map and std::set have the member function equal_range() returning an iterator range of values for a certain key. How does this make sense when std::map and std::set a...
Garwin asked 1/5, 2024 at 8:36

3

Solved

Language: C++ One thing I can do is allocate a vector of size n and store all data and then sort it using sort(begin(),end()). Else, I can keep putting the data in a map or set which are ordered i...
Revitalize asked 6/5, 2018 at 10:49

15

Solved

C++0x is introducing unordered_set, which is available in boost and many other places. What I understand is that unordered_set is hash table with O(1) lookup complexity. On the other hand, set is n...
Copepod asked 28/8, 2009 at 22:42

2

Solved

I am using C++17. std::set is a template type: template< class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> > class set; One can have a std::set ...
Carving asked 19/1, 2023 at 7:40

9

Solved

I have an array of integers that I need to remove duplicates from while maintaining the order of the first occurrence of each integer. I can see doing it like this, but imagine there is a better wa...
Entangle asked 30/8, 2012 at 15:33

5

Solved

Consider the simple program below, which attempts to iterate through the values of a set using NON-const references to the elements in it: #include <set> #include <iostream> class Int...
Tetzel asked 4/8, 2016 at 13:16

6

Solved

I have been trying to find the intersection between two std::set in C++, but I keep getting an error. I created a small sample test for this #include <iostream> #include <vector> #inclu...
Built asked 19/11, 2012 at 5:17

11

Solved

I'm heavily using std::set<int> and often I simply need to check if such a set contains a number or not. I'd find it natural to write: if (myset.contains(number)) ... But because of the ...
Hazelwood asked 1/3, 2017 at 13:4

6

Solved

I have a std::set<int>, what's the proper way to find the largest int in this set?
Disentwine asked 27/8, 2009 at 16:0

5

Solved

I have a std::string. I want the set of unique characters in it, with each character represented as a std::string. I can get the set of characters easily: std::string some_string = ... std::set&l...
Sizing asked 21/4, 2015 at 18:1

8

I need to copy std::set to std::vector: std::set <double> input; input.insert(5); input.insert(6); std::vector <double> output; std::copy(input.begin(), input.end(), output.begin()); ...
Thaine asked 17/2, 2011 at 20:27

1

Solved

Let's use the following code as an example. auto cmp = [](ll a, ll b) { return gcd(12, a) < gcd(12, b); }; set<ll, decltype(cmp)> s(cmp); for(ll i = 0; i < 2; i++){ ll x; cin >&gt...
Bewray asked 1/1, 2021 at 22:35

2

Solved

Suppose I have a set (or map) of strings, and I want to use a custom comparator that compares only the first 5 characters. So "abcde" and "abcdef" are the same in my set. using ...
Oospore asked 5/7, 2020 at 15:1

2

Solved

Does std::set store objects in contiguous memory like std::vector? I haven't been able to find this on the web, cppreference doesn't mention details on memory allocation. But I can't see why it co...
Specific asked 1/1, 2020 at 18:59

5

Solved

An obvious (naive?) approach would be: std::set<int> s; for (int i = 0; i < SIZE; ++i) { s.insert(i); } That's reasonable readable, but from what I understand, not optimal since it inv...
Bigner asked 13/6, 2012 at 14:34

2

Solved

I have a c++ map declared as follows std::map<std::string, int> wordMap= { { "is", 6 }, { "the", 5 }, { "hat", 9 }, { "at", 6 } }; I would like ...
Seaworthy asked 7/6, 2019 at 7:59

3

Solved

The const here is the cause of the compilation problem. However, having implemented an AVL tree myself, I can't understand why. Here's the code: #include <set> int main () { int a; // I ...
Citrange asked 1/2, 2019 at 3:10

2

I am trying to figure out the complexity of erasing multiple elements from std::set. I am using this page as source. It claims that the complexity for erasing a single item using an iterator is am...
Fiorin asked 3/3, 2014 at 9:48

4

Solved

Why can't I have a std::set or std::unordered_set of std::functions? Is there any way to get it to work anyway?
Weirick asked 24/11, 2018 at 15:34

1

Solved

Consider the following data structures and code. struct Sentence { std::string words; int frequency; Sentence(std::string words, int frequency) : words(words), frequency(frequency) {} }; struct...
Butyrin asked 20/11, 2018 at 8:22

2

Solved

I know that std::set does not allow non-const access to it's items. I know that it's impossible to move items out of a the set – because any sort of non-const access might break the ordering of the...
Havens asked 18/8, 2018 at 20:15

2

Solved

I've read this SO post, and this one too regarding the erasure of elements from a std::set during iteration. However, it seems that a simpler solution exists in C++17: #include <set> #includ...
Kamerad asked 8/8, 2018 at 10:15

4

Solved

I would like to know if there is any std library or boost tool to easily merge the contents of multiple sets into a single one. In my case I have some set<int>s which I would like to merge.
Dana asked 17/8, 2011 at 7:57

4

Solved

#include <iostream> #include <set> using namespace std; class StudentT { public: int id; string name; public: StudentT(int _id, string _name) : id(_id), name(_name) { } int getI...

3

Assume I have a std::set (which is by definition sorted), and I have another range of sorted elements (for the sake of simplicity, in a different std::set object). Also, I have a guarantee that all...
Clomp asked 12/4, 2018 at 14:47

© 2022 - 2025 — McMap. All rights reserved.