www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.uni.CodepointSet from range of pairs of integers

reply Carl Sturtivant <sturtivant gmail.com> writes:
I wanted to construct a CodepointSet from a string, so I used the 
constructor here.
https://dlang.org/phobos/std_uni.html#.InversionList.this.2

I wrote a range of pairs (CodepointIntervals) of integers 
consisting of each codepoint in the string paired with that plus 
one. This did solve the problem, but only after I overcame some 
peculiarities of the situation.

Specifically, this required a forward range, not just an input 
range, so I wrote a save method.

Once I fixed that problem, it needed empty() and popFront() to be 
pure. So I added the word pure to each in my range.

Once I fixed that problem, it required those to be  safe, so I 
added that to my struct declaration of my range.

Then everything worked.

Could I have anticipated any of this, and what is the reason for 
each of these?
Feb 18
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
I can understand ``pure``.

https://github.com/dlang/phobos/blob/master/std/uni/package.d#L2075

It is literally on the constructor.

Now  safe I don't know. My best guess would be for some reason the 
constructor is getting inferred as it (templates get inferred).
Feb 18
next sibling parent reply Carl Sturtivant <sturtivant gmail.com> writes:
On Monday, 19 February 2024 at 01:42:03 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 I can understand ``pure``.

 https://github.com/dlang/phobos/blob/master/std/uni/package.d#L2075

 It is literally on the constructor.

 Now  safe I don't know. My best guess would be for some reason 
 the constructor is getting inferred as it (templates get 
 inferred).
What about needing a forward range, not just an input range? It would seem it just needs to iterate through a sequence of pairs of integers.
Feb 18
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 19/02/2024 5:33 PM, Carl Sturtivant wrote:
 On Monday, 19 February 2024 at 01:42:03 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 I can understand ``pure``.

 https://github.com/dlang/phobos/blob/master/std/uni/package.d#L2075

 It is literally on the constructor.

 Now  safe I don't know. My best guess would be for some reason the 
 constructor is getting inferred as it (templates get inferred).
What about needing a forward range, not just an input range? It would seem it just needs to iterate through a sequence of pairs of integers.
Indeed, nothing in that function body would suggest it needs to be a forward range. Ah yup, the body was changed but never updated its template conditional. https://github.com/dlang/phobos/commit/c9f1c42ed3a8bb92e48bf400ce2f31f434a99905
Feb 18
parent Carl Sturtivant <sturtivant gmail.com> writes:
On Monday, 19 February 2024 at 04:47:07 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 19/02/2024 5:33 PM, Carl Sturtivant wrote:
 On Monday, 19 February 2024 at 01:42:03 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
Indeed, nothing in that function body would suggest it needs to be a forward range. Ah yup, the body was changed but never updated its template conditional. https://github.com/dlang/phobos/commit/c9f1c42ed3a8bb92e48bf400ce2f31f434a99905
Thank you for looking into this.
Feb 19
prev sibling parent Carl Sturtivant <sturtivant gmail.com> writes:
On Monday, 19 February 2024 at 01:42:03 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 I can understand ``pure``.

 https://github.com/dlang/phobos/blob/master/std/uni/package.d#L2075

 It is literally on the constructor.
I should have noticed this!
Feb 19