Second class pointers
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 7 22:53:21 PDT 2016
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?
More information about the Digitalmars-d-learn
mailing list