In C++, `std::set`s are a kind of associative container that stores unique elements, and in which the elements themselves are the keys.
Questions tagged [stdset]
294 questions
-1
votes
1 answer
How to refer to the enclosing class member variables from inside of a nested class instance?
As a class member of some class A, I would like to maintain an std::set storing Bs. The set uses a custom comparison object which needs to read a non-static class member, m_t in the example code below, to perform its comparison.
Example code:
class…

Willem3141
- 69
- 7
-1
votes
1 answer
Extract words from the std::set which has the letter 'A' in C++
I have a set of words (BELLOW, CELLO, HAAF, HABIT, HADAL, HAIR, HELLO, HELP, RABIT) stored in std::set datastructure.
From the above set DS, I want to extract words which starts(0th index) with 'H' and store it other container(say…

Rose
- 11
- 6
-1
votes
1 answer
Using std::less for a set of pointers
I've a some class where I'm declaring a set like this:
std::set _retSignalSet;
I'm trying to use std::less compare function on it. I tried something like this:
std::set

Danger69420
- 1
- 3
-1
votes
2 answers
How come 2 uninitialized std::set::iterator are equal?
When std::set<>::iterator is uninitialized, it is not equal to any other iterator in the set, but it is equal to other uninitialized iterators.
Is this GCC-specific implementation? (Is the uninitialized iterator actually initialized to an invalid…

Bill Kotsias
- 3,258
- 6
- 33
- 60
-1
votes
1 answer
How to initialize `std::set` in constructor parameter?
I have a construction that takes a std::set as a parameter.
How do I initialize the set in the constructor parameter?
Here's an minimal conceptual example. Actual implementation is much larger.
#include
enum class Fruits
{
APPLE,…

Thomas Matthews
- 56,849
- 17
- 98
- 154
-1
votes
2 answers
How to verify if there is an element < x in a set C++
Is there an element that is smaller than a given x in a std::set s
If there isn't print "x is the smaller than any element", if there is then print "the biggest element that is smaller than x".
By the way, you also know that x is not in the set
is :…

Alex
- 1
- 3
-1
votes
4 answers
How to empty std::set from objects' pointers?
I am having an issue emptying my set, so I have 3 classes like so:
class A, and 2 inherited classes B and C.
In the code I store elements in my set from the 3 types, the set is:
set objects;
so whenever I create a B element I do that:
A* b =…

ConanCoder
- 39
- 2
- 10
-1
votes
1 answer
Inserting pair in std::set is inconsistent (doesn't recognize .second)
This code performs differently if I add a condition:
First case:
#include
using namespace std;
struct comp
{
bool operator()(pair > a, pair > b)
{
return a.first>b.first;
…

goelakash
- 2,502
- 4
- 40
- 56
-1
votes
1 answer
How to reach elements in a std::set two by two in C++
I have a list of integers.(Currently stored in a std::vector but to increase efficieny, I need to convert it to set. But in current version, I use it as following: (I'm using c++98 not c++11)
int res=0;
vector…

zwlayer
- 1,752
- 1
- 18
- 41
-1
votes
2 answers
How to count no of elements before a given element in std::set
I want to find no of elements present in set before the lower bound of an given element,I thought of using pointer arithmetic with std::set::iterators since they behave like pointer, here is what I tried:
setq;
set::iterator…

Sab
- 485
- 5
- 17
-1
votes
2 answers
how to search in a set in c++
I have a set of a class Item :
std::set - items;
class Item
{
private:
std::string name;
std::string serialNum;
int count;
double unitPrice;
public :
Item(std::string _name, std::string _serialNum, int…

Noam
- 96
- 1
- 12
-1
votes
3 answers
Overloading operator for set
I am using a std::set to implement a specific algorithm. The set had duplicates in it, so I assume I had to overload the operator. The overload looks like this.
class Vec3f {
...
bool operator () ( const Vector3f& v0, const Vector3f& v1 )…

Tring Vu
- 253
- 1
- 10
-1
votes
2 answers
C++, value extracted from the set doesnt appear in set while erasing it from set
I have declared array of sets
std::set _SessionSet[MAX_SESSIONS];
Now I wrote two functions
void insertIntoTrdSessionSet(unsigned char index, md_core::Sample *sample)
{
_SessionSet[index].insert(sample);
}
…

rahul.deshmukhpatil
- 977
- 1
- 16
- 31
-1
votes
2 answers
find_if in set in C++: unresolved overloaded function type
I have used find_if before with lists and vectors in C++ and it has worked fine. But now, when I try to use it with sets I get the following error:
error: no matching function for call to ‘find_if(std::set::iterator,
std::set

FranXh
- 4,481
- 20
- 59
- 78
-1
votes
1 answer
Can't find mistake in using set_difference algorithm
I got:
"object.h"
namespace objectNS
{
class object
{
public:
int m_number;
bool operator== (const object& object) const;
bool operator< (const object& object) const;
};
class compare
{
public:
…

spin_eight
- 3,925
- 10
- 39
- 61