July 05, 2021

Oh my, thank you both, that mostly cleared up my confusion, I had no clue this was struct related.
I'll be reading the references you gave me & probably submitting an issue đź‘Ť

July 05, 2021
On 7/5/21 8:14 AM, Rekel wrote:

> On Monday, 5 July 2021 at 14:22:24 UTC, jfondren wrote:
>> What use of long?
>>
>> remove returns the same type of range as it gets:
>
> My apology, I meant to say countUntil instead of remove in that context.

countUntil says it returns ptrdiff_t, which is the signed version of size_t:

  https://dlang.org/spec/type.html#ptrdiff_t

size_t is an alias of 'long' on 64-bit systems (it would be 'int' on 32-bit systems).

So, you needen't guess the type of count; it is ptrdiff_t :)

  ptrdiff_t index = countUntil(a, element);

However, its common to use 'auto' for return types of most algorithms as they may not be mentionable (although, not in this case; see Voldemort types):

  auto index = countUntil(a, element);

And I always think of 'const' first to prevent silly mistakes:

  const index = countUntil(a, element);

Some other people think of 'immutable' first in the same way:

  immutable index = countUntil(a, element);

All should work in this case but 'const' and 'immutable' will have a "turtles all the way down" behavior which may be cumbersome in some case e.g. when the type has indirections.

Ali

1 2
Next ›   Last »