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 ...
6
Solved
I have a std::set<int>, what's the proper way to find the largest int in this set?
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...
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()); ...
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 >>...
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 ...
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...
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 ...
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 ...
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...
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...
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...
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.
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...
Bosun asked 12/5, 2011 at 4:52
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...
1 Next >
© 2022 - 2025 — McMap. All rights reserved.