Need for (C++20) Contiguous Range

Steven Schveighoffer schveiguy at gmail.com
Thu Oct 8 14:45:47 UTC 2020


On 10/8/20 10:34 AM, Ola Fosheim Grøstad wrote:
> On Thursday, 8 October 2020 at 14:18:45 UTC, Ola Fosheim Grøstad wrote:
>> Or a method slice() that return the container as a slice? In c++ 
>> containers have data and length, so I guess that is an option too.
> 
> To elaborate, c++ containers have a member data() that points to the 
> beginning of the contiguous buffer and a member size() that indicates 
> the number of elements. D has a way to indicate length, but I don't 
> think there is any commonly used data() equivalent? Although one 
> probably could define a freestanding function that can be overloaded? 
> Then you could just test with the compiles trait.
> 

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).

-Steve


More information about the Digitalmars-d mailing list