ndslice of an array structure member?

Jay Norwood via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 21 15:59:07 PST 2015


I'm trying to learn ndslice.  It puzzles me why t3 compiles ok, 
but t4 causes a compiler error in the example below.  Should I be 
able to slice a struct member that is an array?

import std.stdio;
import std.experimental.ndslice;
import std.experimental.ndslice.iteration: transposed;
struct sample{
	ulong [10] core_ctr;
}

struct block{
	ulong[60] samples;
}

void main() {
	auto a1 = new sample[60];
	auto t3 = a1.sliced!(ReplaceArrayWithPointer.no)(3,4,5);
	auto b1 = new block;
	auto t4 = b1.samples.sliced!(ReplaceArrayWithPointer.no)(3,4,5);
}

====== results in error
************  Building D project: nd4  ************
>> Running: "C:\Program Files\dub\dub.exe" build
Performing "debug" build using dmd for x86.
dip80-ndslice 0.8.4: target for configuration "library" is up to 
date.
nd4 ~master: building configuration "application"...
src\app.d(16,58): Error: template 
std.experimental.ndslice.slice.sliced cannot deduce function from 
argument types !(cast(Flag)false)(ulong[60], int, int, int), 
candidates are:
C:\Users\rlxv10\AppData\Roaming\dub\packages\dip80-ndslice-0.8.4\source\std\experimental\ndslice\slice.d(39,6):        std.experimental.ndslice.slice.sliced(Flag mod = ReplaceArrayWithPointer.yes, Range, Lengths...)(Range range, Lengths lengths) if (!isStaticArray!Range && !isNarrowString!Range && allSatisfy!(isIndex, Lengths) && Lengths.length)
C:\Users\rlxv10\AppData\Roaming\dub\packages\dip80-ndslice-0.8.4\source\std\experimental\ndslice\slice.d(47,6):        std.experimental.ndslice.slice.sliced(Flag mod = ReplaceArrayWithPointer.yes, uint N, Range)(Range range, auto ref size_t[N] lengths, size_t shift = 0) if (!isStaticArray!Range && !isNarrowString!Range && N)
C:\Users\rlxv10\AppData\Roaming\dub\packages\dip80-ndslice-0.8.4\source\std\experimental\ndslice\slice.d(116,1):        std.experimental.ndslice.slice.sliced(Names...) if (Names.length && !anySatisfy!(isType, Names) && allSatisfy!(isStringValue, Names))
dmd failed with exit code 1.
   ^^^ Terminated, exit code: 2 ^^^



More information about the Digitalmars-d-learn mailing list