[Issue 15685] New: &slice[$] should be allowed
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Feb 15 03:27:59 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15685
Issue ID: 15685
Summary: &slice[$] should be allowed
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: naptimeentertainment at gmail.com
It should be possible to get the address of the upper boundary of a slice by
taking the address of slice[$]. Here is the address I want (and I hereby
release this untested code snippet into the public domain):
pragma (inline, true) inout(Elem)*
addrOfDollar(Elem) (auto ref inout(Elem)[] slice) @trusted
{
import core.stdc.stdint : uintptr_t;
immutable uintptr_t
pHead = cast(uintptr_t) slice.ptr, // &slice[0]
nmemb = slice.length,
esize = Elem.sizeof,
pDoll = nmemb * esize + pHead; // &slice[$]
return cast(typeof(return)) pDoll;
}
But there are two issues with that:
1. I want to use the syntax &slice[$] instead of calling a function.
2. It doesn't work during CTFE.
--
More information about the Digitalmars-d-bugs
mailing list