Need for (C++20) Contiguous Range
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.com
Thu Oct 8 17:45:30 UTC 2020
On 10/8/20 12:42 PM, Steven Schveighoffer wrote:
> 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);
enum bool isDynamicArray(T) = is(DynamicArrayTypeOf!T) &&
!isAggregateType!T;
Is that again about supporting enums? Sigh.
More information about the Digitalmars-d
mailing list