Generalize .ptr to RawPtr ranges?
Brad Anderson via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 5 15:36:49 PDT 2015
On Monday, 5 October 2015 at 10:06:04 UTC, Dmitry Olshansky wrote:
> Just a random idea - slices have .ptr and therefor have a bunch
> of advantages such as SSE optimized copy routine.
>
> Once I wrap a slice in something (anything) it looses ALL of
> that.
> Now for instance std.container.Array!int.Range can easily
> provide .ptr property, together with .length it would allow us
> to use memcpy etc.
>
> Maybe generalize to isRandomAccessRange!Range +
> hasRawPtr!Range, where hasRawPtr!(Range) would test for
> compatible .ptr and .length.
>
> The benefit compared to manually slicing the .ptr and using
> that, then propagating the change back to the original range is
> that:
> - it's error prone
> - awkwardly replicated at each call site
>
> So it would be much better to retain safe range interface and
> encapsulate speed-hacks inside of the algorithms.
>
> Thoughts?
Somewhat related, C++17 is going to add the concept of Contiguous
Iterators.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3884.pdf
More information about the Digitalmars-d
mailing list