C++ Logo


Advanced search

Colony/hive & unordered vs ordered == operator

From: Matt Bentley <mattreecebentley_at_[hidden]>
Date: Tue, 15 Mar 2022 13:20:41 +1300
Hi Everyone,
quick question:
colony/hive is unordered in terms of insertion position (but sortable),
should the ==/!= operator also be unordered ie.
should hive<int> {1,2, 3} == hive<int> {3, 1, 2}?

My main interest is not which is more 'correct' but which is more useful
in practice?
I don't use == operator for containers a lot so I don't know.
Be aware this will affect >= < etc also.

The unordered version of the operator is trivial, but slower -
it allocates pointers to each of the elements in each of the containers,
then sorts the pointers via the values they point to, then does a
standard == left-hand/right-hand compare via the pointers.
This means (a) == allocates, (b) == is slower due to jumping around in
memory and not necessarily following element sequence.


BTW lewg hive discussion next week, for those who are a part of lewg

Received on 2022-03-15 00:20:45