Second class pointers
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 7 23:17:43 PDT 2016
On Friday, 8 July 2016 at 05:53:21 UTC, Nicholas Wilson wrote:
> So as part of my effort to get D running on GPUs I need to make
> a "second class" pointer type that I can alter in the backend
> of LDC to the correct address space. to that end I have made
> the following
>
> module dcompute.types.pointer;
>
> enum Private = 0;
> enum Global = 1;
> enum Shared = 2;
> enum Constant = 3;
> enum Generic = 4;
>
> pure @trusted nothrow @nogc
> struct Pointer(uint p, T) if(p <= Generic)
> {
> T* ptr;
> ref T opUnary(string op)() if(op=="*")
> {
> return *ptr;
> }
> ref T opIndex(size_t i)
> {
> return *(ptr+i);
> }
> auto opBinary(string op)(ptrdiff_t i) if(op=="+" || op ==
> "-")
> {
> return Pointer!(p, T) (ptr + i);
> }
> }
>
> is there anything else that I'm missing that you can do with a
> raw pointer?
That should be mixin("ptr"~op~"i")
I need compound add and compound subtract as well.
More information about the Digitalmars-d-learn
mailing list