Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ feature, like std::set, which allows duplicates

I have an std::set, which stores std::pairs of two integers. The std::set is also sorted, by allowing me to pass a helping class. However, I have written many lines of code so far and now, at the last tests, "they" told me something, that actually means that I need to allow possible duplicates in the std::set. Of course this isn't done with std::set. Any alternative that will not make me change the whole-big project?

In short, I use the std::set as an ordered list with data an std::pair of two ints.

like image 646
gsamaras Avatar asked Jan 20 '14 02:01

gsamaras


People also ask

Is duplicate data allowed in Set in C++?

In Set duplicate values are not allowed to get stored. On other hand in case of MultiSet we can store duplicate values. In case of Set, one cannot change the value once it gets inserted however we can delete or insert it again. However in case of MultiSet also we cannot change the value once get inserted.

Can you have duplicates in a Set?

A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.

Does unordered Set allow duplicates?

Unordered sets do not allow duplicates and are initialized using comma-delimited values enclosed in curly braces.

How do you find duplicates in a Set?

One more way to detect duplication in the java array is adding every element of the array into HashSet which is a Set implementation. Since the add(Object obj) method of Set returns false if Set already contains an element to be added, it can be used to find out if the array contains duplicates in Java or not.


1 Answers

You can use std::multiset. That should work for what you are describing.

like image 54
R Sahu Avatar answered Nov 13 '22 23:11

R Sahu