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
@bearophile:
Got it. Had it mostly worked out before reading, but this helps clarify
the static foreach part.
Thanks, gang!
Jason
== 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)
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
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
== 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
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;
>> }
>> ...
>>
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)
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
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;
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
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 <=
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[]
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
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;
}
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"
== 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
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
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
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
20 matches
Mail list logo