use of typeof to determine auto type with ndslice examples

lobo via Digitalmars-d-learn digitalmars-d-learn at
Sun Dec 20 20:37:03 PST 2015

On Monday, 21 December 2015 at 04:20:16 UTC, Jay Norwood wrote:
> I pulled down the std.experimental.ndslice examples and am 
> attempting to build some of the examples and understand the 
> types being used.
> I know don't need all these imports, but it is hard to guess 
> which ones are needed, and the examples often don't provide 
> them, which I suspect is a common gripe here.
> Anyway, I was expecting to be able to use the typeof pragma to 
> print a type that could use as a fully specified type, and that 
> doesn't seem to be the case.  I get a compile error instead.
> DMD32 D Compiler v2.069.2 on win32, "dip80-ndslice": "~>0.8.4"
> Is there some other way to get a valid fully specified type for 
> these sliced auto variables?
> import std.stdio;
> import std.experimental.ndslice;
> void main() {
>     import std.algorithm.iteration: map;
>     import std.array: array;
>     import std.range;
>     import std.traits;
>     auto t0 = 1000.iota.sliced(3, 4, 5);
>     pragma(msg, typeof(t0));
>     Slice!(3u, Result) = 1000.iota.sliced(3, 4, 5);
> Slice!(3u, Result)
> src\app.d(12,2): Error: undefined identifier 'Result'
> dmd failed with exit code 1.

No way that I know of. I've had this before with iota and its 
various forms. I have done this in the past:
(or something similar, I haven't got my code handy ATM)

alias RESULT = typeof(iota(1, 2, 3));
Slice!(3u, RESULT) = 1000.iota.sliced(3, 4, 5);

Note that iota(1) and iota(1, 2, 3) return different types so you 
would require two different RESULT aliases.


More information about the Digitalmars-d-learn mailing list