digitalmars.D - Should this invariant always hold? equal(range.retro.array,
- FeepingCreature (5/5) Oct 17 2022 Trolling a bit: Should this invariant always hold?
- ag0aep6g (3/5) Oct 17 2022 No, it shouldn't. The first expression might consume `range`. So
- FeepingCreature (3/10) Oct 17 2022 Ah, good idea!
- Dukc (10/12) Oct 17 2022 Posting this without having looked at other replies.
- FeepingCreature (7/12) Oct 17 2022 Solution, or rather, Phobos code that violates it (even the
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/7) Oct 17 2022 Not an entirely unique case. ;)
Trolling a bit: Should this invariant always hold? assert(equal(range.retro.array, range.array.retro)); Can you find a definition of `range`, using only `std.algorithm` verbs (ie. no custom ranges), that violates it? (And no peeking at my recently-filed bug reports!)
Oct 17 2022
On Monday, 17 October 2022 at 11:02:07 UTC, FeepingCreature wrote:Trolling a bit: Should this invariant always hold? assert(equal(range.retro.array, range.array.retro));No, it shouldn't. The first expression might consume `range`. So it might be empty in the second expression.
Oct 17 2022
On Monday, 17 October 2022 at 11:46:35 UTC, ag0aep6g wrote:On Monday, 17 October 2022 at 11:02:07 UTC, FeepingCreature wrote:Ah, good idea! assert(equal(range.save.retro.array, range.save.array.retro));Trolling a bit: Should this invariant always hold? assert(equal(range.retro.array, range.array.retro));No, it shouldn't. The first expression might consume `range`. So it might be empty in the second expression.
Oct 17 2022
On Monday, 17 October 2022 at 11:02:07 UTC, FeepingCreature wrote:Trolling a bit: Should this invariant always hold? assert(equal(range.retro.array, range.array.retro));Posting this without having looked at other replies. No. The range could be a reference range, in which case this does not hold unless the range is already empty. The invariant would have to be `assert(equal(range.save.retro.array, range.save.array.retro));` instead. Also this won't hold if the range contains floating point NaNs, or other elements that are not equal to themselves. There may be other corner cases too I didn't think of.
Oct 17 2022
On Monday, 17 October 2022 at 11:02:07 UTC, FeepingCreature wrote:Trolling a bit: Should this invariant always hold? assert(equal(range.retro.array, range.array.retro)); Can you find a definition of `range`, using only `std.algorithm` verbs (ie. no custom ranges), that violates it? (And no peeking at my recently-filed bug reports!)Solution, or rather, Phobos code that violates it (even the strengthened `assert(equal(range.save.retro.array, range.save.array.retro))`): [rot13](https://rot13.com/): `nhgb enatr = bayl(1, 2).havd!"gehr"; // havd onpxjneq vgrengvba purpxf ryrzragf sbe havdhrarff va gur onpxjneq beqre bs gur haqreylvat enatr.`
Oct 17 2022
On 10/17/22 23:19, FeepingCreature wrote:[rot13](https://rot13.com/): `nhgb enatr = bayl(1, 2).havd!"gehr"; // havd onpxjneq vgrengvba purpxf ryrzragf sbe havdhrarff va gur onpxjneq beqre bs gur haqreylvat enatr.`Not an entirely unique case. ;) https://issues.dlang.org/show_bug.cgi?id=16588 Ali
Oct 17 2022