C++ Logo

sg14

Advanced search

Re: Colony/hive & unordered vs ordered == operator

From: Matt Bentley <mattreecebentley_at_[hidden]>
Date: Wed, 16 Mar 2022 12:05:24 +1300
On 16/03/2022 2:45 am, Henry Miller via SG14 wrote:
> If there is an operator == it must be ordered! Nothing in the standard guarantees that hive<int> {1,2, 3} == hive<int> {1,2, 3} if == is unordered. While that is an

Maybe I'm misunderstanding you, but as Arthur already mentioned,
std::unordered_set has an unordered == operator. Which Does guarantee
that hive<int> {1,2, 3} == hive<int> {1,2, 3}, as well as hive<int>
{1,2, 3} == hive<int> {3,1, 2}.


> Ordered operator== is a lot more complex. Is operator== const, non-const, or both?

It's not more complex, it's less complex. And unordered is only
trivially more-complex than ordered. As mentioned, there is no sorting
of container elements.
It is still O(n), despite what some people have written here - it's just
that there are 2 passes over n, rather than 1.
Again I am more swayed by practical arguments than non-practical. So if
anyone has any strong experience of using == comparisons in containers
in general, please say your piece.
Only insertion position is unordered in hive/colony - otherwise
sequences don't change, and the container can be sorted as mentioned.


> We probably should clean up the above arguments and put them directly into the paper (an appendix) so that they are easy to find in 10 years when this comes up again.
>

Probably a Good idea - but this will probably happen after LEWG (11am
pacific time, 22nd).

Received on 2022-03-15 23:05:31