return type based on content of an array

2018-02-20 Thread thorstein via Digitalmars-d-learn
Hi, I'm going circles... ;) I read a string that contains an array of unknown dimension like: a = [1,2,3,4] or a = [[1,2],[3,4]] or a = [[[1,2],[3,4]],[[5,6],[7,8]]] With that I want to perform specified operations e.g. also provided on command line. Because at compile time the dimension

Re: Manually allocating a File

2018-02-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 21, 2018 02:59:21 Nicholas Wilson via Digitalmars-d- learn wrote: > On Tuesday, 20 February 2018 at 15:32:45 UTC, Chris M. wrote: > > Thanks for the info, that clears things up. Like I said, it was > > more experimentation rather than me planning to actually use > > it.

Re: Manually allocating a File

2018-02-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 15:32:45 UTC, Chris M. wrote: Thanks for the info, that clears things up. Like I said, it was more experimentation rather than me planning to actually use it. Works now with the following modifications. import std.stdio; import core.stdc.stdlib; import

Re: Link to https://run.dlang.io/ ??

2018-02-20 Thread Seb via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 14:45:55 UTC, Dennis wrote: I recently tried to go to that site, and I tried `run.dlang.com` which is the wrong URL. So I was looking through the D homepage for the right link but couldn't find it. Even a Google search for "online d compiler" or "run dlang

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:20:45 UTC, Smaehtin wrote: On Tuesday, 20 February 2018 at 16:15:56 UTC, Radu wrote: On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() {

Re: Can someone help a Reddit user

2018-02-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/20/18 2:00 PM, bachmeier wrote: Someone has posted a question on our subreddit. Would be nice if he could get an answer: https://www.reddit.com/r/d_language/comments/7yxwvm/why_do_my_threads_write_to_the_wrong_file/ I responded. Looks to me like a race condition in the DMC libc code,

Can someone help a Reddit user

2018-02-20 Thread bachmeier via Digitalmars-d-learn
Someone has posted a question on our subreddit. Would be nice if he could get an answer: https://www.reddit.com/r/d_language/comments/7yxwvm/why_do_my_threads_write_to_the_wrong_file/

Re: Trying to forward unwrapped opDispatch names to alias this

2018-02-20 Thread aliak via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:12:17 UTC, Adam D. Ruppe wrote: On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote: T is the wrapped type. So if T has a member (in the example it's the built in field "max") then forward that. Oh, I see what you mean. So the problem is that built in

Re: Trying to forward unwrapped opDispatch names to alias this

2018-02-20 Thread aliak via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 11:27:23 UTC, Alex wrote: There is a related ticket, https://issues.dlang.org/show_bug.cgi?id=6434 However, not exactly facing this question. Should that ticket be marked as resolved? The issue is for alias this to be considered before opDispatch but there were

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:15:56 UTC, Radu wrote: On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!(

Re: Capturing by reference with "visit" from std.variant

2018-02-20 Thread Radu via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 16:01:11 UTC, Smaehtin wrote: I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!( (ref string s) { s = "Why does this not work?"; }

Re: Trying to forward unwrapped opDispatch names to alias this

2018-02-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote: T is the wrapped type. So if T has a member (in the example it's the built in field "max") then forward that. Oh, I see what you mean. So the problem is that built in types don't have "members" per se, they have "magic". The built in

Capturing by reference with "visit" from std.variant

2018-02-20 Thread Smaehtin via Digitalmars-d-learn
I'm trying to understand why the following doesn't work: import std.stdio; import std.variant; void main() { Algebraic!(string, int) test = "Test"; test.tryVisit!( (ref string s) { s = "Why does this not work?"; } ); writeln(test); } But this works fine:

Re: Manually allocating a File

2018-02-20 Thread Chris M. via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 15:18:11 UTC, Adam D. Ruppe wrote: On Tuesday, 20 February 2018 at 14:56:54 UTC, Chris M. wrote: I'm doing this mainly for experimentation, but the following piece of code gives all sorts of errors. so important note: this will perform worse than the automatic

Re: Generic Property Implementation

2018-02-20 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 14:34:53 UTC, bauss wrote: Would there be a reason why this wouldn't be a good implementation? What is the intended use case for this? The main feature seems to be an ability to have read-only members, which is nice. Are there other benefits? If so what

Re: Manually allocating a File

2018-02-20 Thread Uknown via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 14:56:54 UTC, Chris M. wrote: I'm doing this mainly for experimentation, but the following piece of code gives all sorts of errors. Hangs, segfaults or prints nothing and exits import std.stdio; import core.stdc.stdlib; void main() { auto f = cast(File *)

Re: Manually allocating a File

2018-02-20 Thread Uknown via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 15:21:59 UTC, Uknown wrote: On Tuesday, 20 February 2018 at 14:56:54 UTC, Chris M. wrote: void main() [snip] Never mind, I confused FILE* with File...

Re: Manually allocating a File

2018-02-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 14:56:54 UTC, Chris M. wrote: I'm doing this mainly for experimentation, but the following piece of code gives all sorts of errors. so important note: this will perform worse than the automatic allocation, which just puts it down in-place. You should basically

Manually allocating a File

2018-02-20 Thread Chris M. via Digitalmars-d-learn
I'm doing this mainly for experimentation, but the following piece of code gives all sorts of errors. Hangs, segfaults or prints nothing and exits import std.stdio; import core.stdc.stdlib; void main() { auto f = cast(File *) malloc(File.sizeof); *f = File("test.txt", "r");

Re: Link to https://run.dlang.io/ ??

2018-02-20 Thread Dennis via Digitalmars-d-learn
I recently tried to go to that site, and I tried `run.dlang.com` which is the wrong URL. So I was looking through the D homepage for the right link but couldn't find it. Even a Google search for "online d compiler" or "run dlang online" didn't turn up anything directly, I had to go through the

Generic Property Implementation

2018-02-20 Thread bauss via Digitalmars-d-learn
Would there be a reason why this wouldn't be a good implementation? If so what and how could it be improved? Are there flaws in an implementation like this? struct Property(T, bool readOnly = false) { import std.traits : isScalarType, isArray, isAssociativeArray, isSomeString;

Re: How to make AA key a pointer

2018-02-20 Thread Clinton via Digitalmars-d-learn
On Monday, 19 February 2018 at 15:02:29 UTC, ketmar wrote: Clinton wrote: On Monday, 19 February 2018 at 14:55:01 UTC, Clinton wrote: [...] Sorry, on second look my explanation isn't very clear. I want to know if: bool[string] myAA; myAA[contact.id] = true; // Does this copy contact.id

Link to https://run.dlang.io/ ??

2018-02-20 Thread ShadoLight via Digitalmars-d-learn
It would be nice if there was a link to https://run.dlang.io/ on the dlang website - preferably under Resources drop-down menu or similar. Or is there somewhere and I am just missing it? I have bookmarked it for myself, but it would be better for newbies if it was also easily accessible from

Re: Trying to forward unwrapped opDispatch names to alias this

2018-02-20 Thread Alex via Digitalmars-d-learn
On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote: On Monday, 19 February 2018 at 01:00:23 UTC, Adam D. Ruppe wrote: On Monday, 19 February 2018 at 00:42:05 UTC, aliak wrote: struct B(T) { T t; A a; alias a this; auto opDispatch(string name)() if (hasMember!(T, name)) {

Re: countUntil to print all the index of a given string.

2018-02-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 20, 2018 08:44:37 aberba via Digitalmars-d-learn wrote: > On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: > > On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: > >> [...] > > > > Just thought of a much better/simpler solution for that last > > case that also

Re: countUntil to print all the index of a given string.

2018-02-20 Thread aberba via Digitalmars-d-learn
On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: [...] Just thought of a much better/simpler solution for that last case that also doesn't force you to read all data (which might be impossible when dealing with infinite