Re: Singleton in Action?

2019-02-03 Thread Dejan Lekic via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example

Re: How can I walk the list in a RegexMatch backwards?

2019-02-03 Thread Jordan Wilson via Digitalmars-d-learn
On Sunday, 3 February 2019 at 18:07:13 UTC, Chris Bare wrote: auto matches = matchAll(str, searchRegex); foreach (m; matches) // this walks the list forward I tried: foreach_reverse (m; matches) foreach (m; reverse (matches)) foreach (m; retro (matches)) and they all failed to compile. I also

Re: Singleton in Action?

2019-02-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-02 17:56, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example for how one would actually

How can I walk the list in a RegexMatch backwards?

2019-02-03 Thread Chris Bare via Digitalmars-d-learn
auto matches = matchAll(str, searchRegex); foreach (m; matches) // this walks the list forward I tried: foreach_reverse (m; matches) foreach (m; reverse (matches)) foreach (m; retro (matches)) and they all failed to compile. I also tried to index matches (matches[i]) but that does not work

Re: static arrays at runtime with templates ?

2019-02-03 Thread Emil via Digitalmars-d-learn
On Sunday, 3 February 2019 at 16:36:30 UTC, Paul Backus wrote: ... This is actually already in the standard library: https://dlang.org/phobos/std_array.html#staticArray thank you either I already read that and forgot or finally I'm starting to get the feel of the language :)

Re: static arrays at runtime with templates ?

2019-02-03 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 3 February 2019 at 16:33:48 UTC, Emil wrote: I tried this on a whim and it appears to work: auto static_array(T, size_t data_size)() { T[data_size] data; return data; } This is actually already in the standard library: https://dlang.org/phobos/std_array.html#staticArray

static arrays at runtime with templates ?

2019-02-03 Thread Emil via Digitalmars-d-learn
I tried this on a whim and it appears to work: auto static_array(T, size_t data_size)() { T[data_size] data; return data; } void main() { import std.stdio: writeln; import std.traits: isStaticArray; auto data = static_array!(int, 5)(3); writeln(data); static

Re: Singleton in Action?

2019-02-03 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2019-02-03 at 14:42 +, Ron Tarrant via Digitalmars-d-learn wrote: > On Sunday, 3 February 2019 at 10:28:51 UTC, Alex wrote: > > > Isn't deriving a singleton even eviler as having one? ;) > > Perhaps this was meant as rhetoric, but I think you may be right. > > This morning I was

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 10:28:51 UTC, Alex wrote: Isn't deriving a singleton even eviler as having one? ;) Perhaps this was meant as rhetoric, but I think you may be right. This morning I was Googling "singleton replacement" and someone on another forum said Factory would do the job.

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 11:17:38 UTC, Jonathan M Davis wrote: I don't recall std.thread ever existing, and std.c.time hasn't been around for a while. Thread is in core.thread, and all of the C bindings for standard C and OS APIs are supposed to be in druntime. So, the equivalent to C's

Re: Singleton in Action?

2019-02-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 3, 2019 2:41:48 AM MST Ron Tarrant via Digitalmars-d- learn wrote: > On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: > > https://rosettacode.org/wiki/Singleton#D > > Do you know if this is for a current version of D? The compiler > is choking on the import

Re: Singleton in Action?

2019-02-03 Thread Alex via Digitalmars-d-learn
On Sunday, 3 February 2019 at 09:46:20 UTC, Ron Tarrant wrote: On Saturday, 2 February 2019 at 20:30:15 UTC, Neia Neutuladh wrote: And consider putting the class in its own source file. Yes, by all means. Speaking of which... Considering the nature of a singleton such the one in the top

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 20:30:15 UTC, Neia Neutuladh wrote: And consider putting the class in its own source file. Yes, by all means. Speaking of which... Considering the nature of a singleton such the one in the top post, I can't see it being possible to use one as a base class

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: https://rosettacode.org/wiki/Singleton#D Do you know if this is for a current version of D? The compiler is choking on the import statements, complaining that it can't read std/thread.d and std/c/time.d

Re: Singleton in Action?

2019-02-03 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 2 February 2019 at 19:40:25 UTC, Andre Pany wrote: I found here an example: https://rosettacode.org/wiki/Singleton#D Kind regards Andre Thanks, Andre. Exactly what I was hoping for.