Testing for RandomAccessRange on strings

Etienne etcimon at globecsys.com
Sat Jan 18 11:23:16 PST 2014


I'm trying to make a memory controller that has a cache and works only 
with malloc allocations (no GC). My problem is that I need to be able to 
copy ranges of bytes like this

target[] = mem[]

basically, it works for char[], dchar[], ubyte[] etc.

I can't really decide myself on what should be the generic test here 
because RandomAccessRange doesn't work, opIndex doesn't exist, and I'd 
want my memory controller to be able to accept classes that look like this:

class CombinedMemoryElement {
	string name;
	uint accessed;
	size_t hash;
	ubyte opIndex(size_t pos);
	ubyte[] opSlice(size_t start, size_t end);
...opDollar...
}

With data serialization in opIndex / opSlice.

So I thought of something like

static if (__traits(compiles, T.init[$]));

Where T would be CombinedMemoryElement[] in

but it looks too much like a hack. Did we end up with a concept in D 
that defines this specific purpose of ranges?


More information about the Digitalmars-d mailing list