acco93
acco93

Reputation: 138

Iteration order of std::unordered_set

Does the same code using std::unordered_set (or std::unordered_map) run on two different machines and compiled with the same exact g++ version give the same iteration order?

Related but slightly different question


I'm adding a few comments here to better explain what I'm trying to understand.

Is it enough to fix the compiler version in order to get the same behavior, in this case in terms of iteration order? Or does it depend on some other things?

Thank you for pointing out that the standard does not impose any behavior. However, the implementation must be clearly defined. In the end, it is computer code and thus it is deterministic and well-defined. The only alternative that comes to my mind is that some crazy implementation might use some real source of randomization, but I think it is very unlikely.

Upvotes: 1

Views: 732

Answers (1)

Bathsheba
Bathsheba

Reputation: 234695

There's nothing in the C++ standard to suggest it ought to.

g++ doesn't appear to have any documentation specifying above and beyond what the standard requires on this particular topic.

I'd say no then, in full generality.

Upvotes: 2

Related Questions