Re: various questions

2010-08-03 Thread Rory Mcguire
Jason Spencer wrote: > == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article >> Jason Spencer wrote: >> > == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article >> >> Jason Spencer wrote: >> > >> >> > I nievely went and replaced "foreach (t; > Iota!(str_types.length))" >> >> > wit

Re: various questions

2010-07-31 Thread Jason Spencer
@bearophile: Got it. Had it mostly worked out before reading, but this helps clarify the static foreach part. Thanks, gang! Jason

Re: various questions

2010-07-31 Thread Jason Spencer
== Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article > Jason Spencer wrote: > > == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article > >> Jason Spencer wrote: > > > >> > I nievely went and replaced "foreach (t; Iota!(str_types.length))" > >> > with "foreach (t; str_types.length)

Re: various questions

2010-07-30 Thread bearophile
Jason Spencer: > I nievely went and replaced "foreach (t; Iota!(str_types.length))" > with "foreach (t; str_types.length)", since the length of that array > is known at compile-time. That of course bombed, but I don't quite > get why. Is the compiler actually evaluating the foreach loop at > comp

Re: various questions

2010-07-30 Thread Rory Mcguire
Jason Spencer wrote: > == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article >> Jason Spencer wrote: > >> > I nievely went and replaced "foreach (t; Iota!(str_types.length))" >> > with "foreach (t; str_types.length)", since the length of that >> > array is known at compile-time. > >> yo

Re: various questions

2010-07-30 Thread Jason Spencer
== Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article > Jason Spencer wrote: > > I nievely went and replaced "foreach (t; Iota!(str_types.length))" > > with "foreach (t; str_types.length)", since the length of that > > array is known at compile-time. > your replacement tries to loop over

Re: various questions

2010-07-29 Thread Rory Mcguire
Jason Spencer wrote: > Ok, I've gone over this, adapted it, and mostly understand it. I just > have one question left: > > == Quote from bearophile (bearophileh...@lycos.com)'s article >> template Iota(int stop) { >> ... >> alias TypeTuple!(Iota!(stop-1), stop-1) Iota; >> } >> ... >>

Re: various questions

2010-07-29 Thread Jason Spencer
Ok, I've gone over this, adapted it, and mostly understand it. I just have one question left: == Quote from bearophile (bearophileh...@lycos.com)'s article > template Iota(int stop) { > ... > alias TypeTuple!(Iota!(stop-1), stop-1) Iota; > } > ... > foreach (t; Iota!(str_types.length)

Re: various questions

2010-07-29 Thread Steven Schveighoffer
ork on static arrays of the proper size, and template that up for the different sizes I need to support. I appeal to your experience and mercy on the various questions below. Any help on any point appreciated. 1. How can I cast a single dimension dynamic array to a multi-dimension static a

Re: various questions

2010-07-29 Thread Kagamin
Kagamin Wrote: > Jason Spencer Wrote: > > > If I want to avoid the copy, am I relegated back > > to pointers? > or something like this struct ReferenceArray!(ArrayType) { ArrayType* back; this(byte[] data) { assert(data.length==ArrayType.sizeof); back = cast(ArrayType*)data.ptr;

Re: various questions

2010-07-29 Thread Kagamin
Jason Spencer Wrote: > If I want to avoid the copy, am I relegated back > to pointers? you can make a thin wrapper that will work as a reference-type static array struct ReferenceArray!(ElementType, int columns, int rows) { ElementType[columns][rows]* back; this(byte[] data) { assert(d

Re: various questions

2010-07-28 Thread Jason Spencer
That's COOL! I'll have to look at these closer, but I definitely get what you're doing. Thanks a million. == Quote from bearophile (bearophileh...@lycos.com)'s article > Simpler: > import std.stdio: writeln; > import std.typetuple: TypeTuple; > template Iota(int stop) { > static if (stop <=

Re: various questions

2010-07-28 Thread bearophile
Last version for now, it can be improved further in various ways: import std.typetuple: TypeTuple; import std.metastrings: Format; template Iota(int stop) { static if (stop <= 0) alias TypeTuple!() Iota; else alias TypeTuple!(Iota!(stop-1), stop-1) Iota; } enum string[]

Re: various questions

2010-07-28 Thread bearophile
Simpler: import std.stdio: writeln; import std.typetuple: TypeTuple; template Iota(int stop) { static if (stop <= 0) alias TypeTuple!() Iota; else alias TypeTuple!(Iota!(stop-1), stop-1) Iota; } void foo(T, int N, int M)() { writeln(typeid(T), " ", N, " ", M); } enum

Re: various questions

2010-07-28 Thread bearophile
This is better, probably it can be improves a bit more: import std.stdio: writeln; import std.metastrings: Format; import std.typetuple: TypeTuple; template Iota(int stop) { static if (stop <= 0) alias TypeTuple!() Iota; else alias TypeTuple!(Iota!(stop-1), stop-1) Iota; }

Re: various questions

2010-07-28 Thread bearophile
Jason Spencer: > I had thought of the switch, and it would be too large. Can you give me an > idea of what > the mixin solution would look like? Suppose I have three strings, type, > rows, and cols > that get set at runtime, where type = ["int" | "float" | "short"], rows and > cols = > ["100"

Re: various questions

2010-07-28 Thread Jason Spencer
== Quote from bearophile (bearophileh...@lycos.com)'s article Thanks for all the suggestions! A little more discussion: > > So I need some slick way of mapping the run-time element size, row count, > > and column count into a static array type to instantiate my template with. > A basic brutal wa

Re: various questions

2010-07-28 Thread bearophile
Jason Spencer: > 1. How can I cast a single dimension dynamic array to a multi-dimension > static array? I'm trying to do roughly the following: >auto data = cast(float[100][100])std.file.read(fname, fsize); I have tried a natural implementation, but it doesn't work and I don't know why it

Re: various questions

2010-07-28 Thread Jason Spencer
Forgot a couple of things: - this is all using D2.047. - Another question (in reference to part 2 before): I'd like to support about 4 base types and 5 or 6 different matrix sizes. So that's roughly 20 type combinations for my template. But I decide these based on command-line arguments at run

various questions

2010-07-28 Thread Jason Spencer
the different sizes I need to support. I appeal to your experience and mercy on the various questions below. Any help on any point appreciated. 1. How can I cast a single dimension dynamic array to a multi-dimension static array? I'm trying to do roughly the following: auto d