Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About set container

std::set<int, std::less_equal<int>> myset = {1,1,7,8,2,2};
myset.insert(99);
myset.insert(99);
for(const int & val : myset)
    std::cout << val << " ";

output:

1 1 2 2 7 8 99 99 

Hello, while i was studying on containers. i realized that when i use less_equal function, standart set container behaves just as a multiset container. Is this normal? if it is, what is the difference between multiset and set?

like image 472
Rıfat Tolga Kiran Avatar asked Feb 28 '26 22:02

Rıfat Tolga Kiran


1 Answers

Is this normal?

No, it is not normal. Your cannot specify std::less_equal as a comparator for std::set because it does not satisfy the strict weak ordering rules.

See the requirements here.

like image 158
Edgar Rokjān Avatar answered Mar 02 '26 14:03

Edgar Rokjān



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!