I have a test randomly failing, I suspect due to order of objects in a std::set ordered on pointers values. However, on my current exe, the test always passes. Is there a way I can "mix" the pointers creations so the order of object in my set is different between two runs ?
In other words, is the "sorted order" (p1 < p2) of pointers deterministic for a given C++ code, or does different compilations or different runs can have different sorted orders ?
For example in this code, adding "p1b.reset(nullptr)" between p1 and p2 creation will invert p1 / p2 "sorted order" . Is there any other way to influence this order, without changing the source code ?
int main(void)
{
std::unique_ptr< MyClass > p1b(new MyClass());
//Lot of code, with memory allocated/deallocated
std::unique_ptr< MyClass > p1(new MyClass());
//p1b.reset(nullptr);
//Lot of code, with memory allocated/deallocated
std::unique_ptr< MyClass > p2(new MyClass());
std::cout << "p1: " << p1.get() << std::endl;
std::cout << "p2: " << p2.get() << std::endl;
}
Gives:
p1: 0x171c030
p2: 0x171c050
With "p1b.reset(nullptr)" commented out:
p1: 0x21f9030
p2: 0x21f9010