Re: Rvalue references

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/18 6:07 PM, Jiyan wrote: Sry i know i asked it already in IRC: Are rvalue references already solved with auto ref? https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it Says rvalues are moved! But an rvalue move is cheaper. You construct

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Seb via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 23:27:42 UTC, H. S. Teoh wrote: On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote: On 09.01.2018 22:04, H. S. Teoh wrote: > [...] I think "if (0 == 3) { static break; }" should be a compile-time error. That's also a possible

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote: > On 09.01.2018 22:04, H. S. Teoh wrote: > > if (0 == 3) {} > > // all subsequent iterations deleted > > > > because the static break is unconditionally compiled (it has nothing > > to do with the runtime

Re: Is there a way to get this associative array initialization to work?

2018-01-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 23:05:21 UTC, WhatMeWorry wrote: source\app.d(148,1): Error: not an associative array initializer The C-style struct initialization in there is a problem. Try making it immutable Sound[string] soundLibrary = // line 148 [ "SCRATCH" :

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Timon Gehr via Digitalmars-d-learn
On 09.01.2018 22:04, H. S. Teoh wrote: if (0 == 3) {} // all subsequent iterations deleted because the static break is unconditionally compiled (it has nothing to do with the runtime branch). You'd have to use static if to make it conditionally-compiled and thus not instantly

Re: Is there a way to get this associative array initialization to work?

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/9/18 6:05 PM, WhatMeWorry wrote: enum SoundType { MUSIC = 0, SOUND_EFFECT }; struct Sound {     string file;     SoundType  musicOrSfx;     void*  ptr;   // Mix_Chunk* for sfx;  Mix_Music* for music; } immutable Sound[string] soundLibrary  =   // line 148 [     "SCRATCH"   

Is there a way to get this associative array initialization to work?

2018-01-09 Thread WhatMeWorry via Digitalmars-d-learn
enum SoundType { MUSIC = 0, SOUND_EFFECT }; struct Sound { string file; SoundType musicOrSfx; void* ptr; // Mix_Chunk* for sfx; Mix_Music* for music; } immutable Sound[string] soundLibrary = // line 148 [ "SCRATCH" : { file : "scratch.wav", musicOrSfx

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 03:26:32PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/9/18 2:31 PM, H. S. Teoh wrote: [...] > > If there were a hypothetical `static continue` or `static break` > > that's recognized by the static foreach unroller, we could in theory > > automate

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/9/18 2:31 PM, H. S. Teoh wrote: On Tue, Jan 09, 2018 at 02:24:11PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] A break or continue is simply a goto underneath. A goto in an unrolled loop isn't much different than a goto in a um... rolled loop :) It's just that there

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 02:24:11PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > A break or continue is simply a goto underneath. A goto in an unrolled > loop isn't much different than a goto in a um... rolled loop :) It's > just that there are copies of each loop body, and

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/9/18 11:35 AM, H. S. Teoh wrote: On Tue, Jan 09, 2018 at 10:57:03AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: I may have been misleading when I made my first comment. What I mean is that you *can't* break or continue a static foreach, even with labels. However, you *can*

Re: Storing struct in a array

2018-01-09 Thread thedeemon via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 18:09:58 UTC, Vino wrote: It is possible to store struct in a array ans use the same in csvReader Sure, you can just pass the type of your struct to csvReader: Array!T1 T1s; reader(fName, T1s); // pass the array Type as a function parameter First you write

Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 17:41:10 UTC, Vino wrote: On Tuesday, 9 January 2018 at 17:00:05 UTC, thedeemon wrote: On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote: Hi All, It is possible to store struct in a array ans use the same in csvReader Sure, you can just pass the type of

Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 17:00:05 UTC, thedeemon wrote: On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote: Hi All, It is possible to store struct in a array ans use the same in csvReader Sure, you can just pass the type of your struct to csvReader: struct Layout { string name;

Re: Storing struct in a array

2018-01-09 Thread thedeemon via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote: Hi All, It is possible to store struct in a array ans use the same in csvReader Sure, you can just pass the type of your struct to csvReader: struct Layout { string name; int value; double other; } auto readArrayOfStructs(string

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 10:57:03AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/8/18 9:27 AM, H. S. Teoh wrote: > > On Sun, Jan 07, 2018 at 10:39:19PM -0500, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > On 1/6/18 6:25 PM, Ali Çehreli wrote: > > > > Is

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/18 9:27 AM, H. S. Teoh wrote: On Sun, Jan 07, 2018 at 10:39:19PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 1/6/18 6:25 PM, Ali Çehreli wrote: Is 'static foreach' sufficient for all needs or is there any value for regular foreach over compile-time sequences? If you

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/18 3:07 PM, Jonathan M Davis wrote: But regardless, labeled break definitely works within a static foreach, and I expect that a labeled continue does as well, but I haven't tried it. I didn't mean it that way, see my reply to H. -Steve

Re: Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote: Hi All, It is possible to store struct in a array ans use the same in csvReader e.g. import std.stdio; import std.container.array; void main () { Array!string a; struct Layout { string name; int value; double other; }

Re: Creating Struct for an output of a program.

2018-01-09 Thread Vino via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 12:50:04 UTC, Mengu wrote: On Tuesday, 9 January 2018 at 07:57:19 UTC, Vino wrote: [...] if S2 consists of data for Layout struct, then you can simply do: auto S2 = S1.map!(a => Layout(a[0], a[1], a[2])); which will give you a range of Layout. Hi, We

Storing struct in a array

2018-01-09 Thread Vino via Digitalmars-d-learn
Hi All, It is possible to store struct in a array ans use the same in csvReader e.g. import std.stdio; import std.container.array; void main () { Array!string a; struct Layout { string name; int value; double other; } a.insert(Layout); auto record =

Re: Creating Struct for an output of a program.

2018-01-09 Thread Mengu via Digitalmars-d-learn
On Tuesday, 9 January 2018 at 07:57:19 UTC, Vino wrote: Hi All, Request your help on how to create a struct with the output of the below program. Program: import std.algorithm: all, map, filter; import std.stdio: File, writeln; import std.typecons: Tuple, tuple; import std.container.array;

Re: Help optimizing UnCompress for gzipped files

2018-01-09 Thread Christian Köstlin via Digitalmars-d-learn
On 07.01.18 14:44, Steven Schveighoffer wrote: > Not from what I'm reading, the C solution is about the same (257 vs. > 261). Not sure if you have averaged these numbers, especially on a real > computer that might be doing other things. yes you are right ... for proper benchmarking proper

Creating Struct for an output of a program.

2018-01-09 Thread Vino via Digitalmars-d-learn
Hi All, Request your help on how to create a struct with the output of the below program. Program: import std.algorithm: all, map, filter; import std.stdio: File, writeln; import std.typecons: Tuple, tuple; import std.container.array; import std.string: split, strip; import std.uni: isWhite,