Need for (C++20) Contiguous Range
Steven Schveighoffer
schveiguy at gmail.com
Thu Oct 8 16:42:51 UTC 2020
On 10/8/20 11:45 AM, IGotD- wrote:
> On Thursday, 8 October 2020 at 14:45:47 UTC, Steven Schveighoffer wrote:
>>
>> We have arrays in D, there is no need to duplicate what C++ does
>> because they don't have a real array type.
>>
>> In D, you would check if the range is a dynamic array, and then use
>> ptr/length to deal with optimizations (I do this in iopipe).
>>
>
> Just clarify, you mean that anything that is continuous memory can be
> converted to a slice (as supposed to an array, even if the relationship
> is somewhat ambiguous is D).
Yes. I have argued in the past
(https://dlang.org/articles/d-array-article.html) that the "true" array
type is hidden in the runtime, and that we should just call T[] a slice.
>
> So if a type with continuous memory storage is converted to a slice,
> will isDynamicArray!T also be valid for the slice?
>
Yes.
I was going to post the code for isDynamicArray, but like many things in
std.traits, it's needlessly complicated.
It should just be:
enum isDynamicArray(T) = is(T == U[], U);
-Steve
More information about the Digitalmars-d
mailing list