std.container.rbtree as Interval Tree?

2019-02-04 Thread James Blachly via Digitalmars-d-learn
I tried to implement an interval tree backed by std.container.rbtree today and fell flat. A standard way to make an interval tree is to make an augmented tree; I supposed since rbtree was a generic container and because I could define opCmp, this should be a cinch. I ran into two problems.

Re: static arrays at runtime with templates ?

2019-02-04 Thread XavierAP via Digitalmars-d-learn
On Monday, 4 February 2019 at 19:14:38 UTC, Emil wrote: Can std.array.staticArray build static arrays with size known only at run time ? Now that I am not overcome with enthousiasm it looks like it too needs to know the size. A static array's size must be known (or computed) at compile time

Re: Singleton in Action?

2019-02-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-04 11:36, Ron Tarrant wrote: I've seen comments similar to this in several examples. When you say "no one else" you're personifying callers? Yes. And so this means: No caller outside the object? Which really amounts to: Since no one INside the object WILL call this() and no one

Re: static arrays at runtime with templates ?

2019-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 04, 2019 at 07:14:38PM +, Emil via Digitalmars-d-learn wrote: [...] > Can std.array.staticArray build static arrays with size known only at > run time ? Now that I am not overcome with enthousiasm it looks like > it too needs to know the size. That's not possible, because the size

Re: static arrays at runtime with templates ?

2019-02-04 Thread Emil via Digitalmars-d-learn
On Monday, 4 February 2019 at 16:08:38 UTC, XavierAP wrote: Static arrays are always allocated at run-time. It's the size of the array that must be known at compile-time (in this case via a template parameter). What's the advantage (or the essential difference) of auto data = static_array!

Submenu Not Responding Until Second Click

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
I posted about this over on the GtkD site, but I suspect no one's home until later in the day. I've been writing up examples for menus and found some odd behaviour. Now I'm wondering if I've missed something. The code compiles without error and runs. But after the window opens, first click o

Re: static arrays at runtime with templates ?

2019-02-04 Thread XavierAP via Digitalmars-d-learn
On Sunday, 3 February 2019 at 16:33:48 UTC, Emil wrote: Is this for real, static arrays at runtime without manually allocating memory ? Is this legitimate or should I expect problems ? Static arrays are always allocated at run-time. It's the size of the array that must be known at compile-t

Re: Singleton in Action?

2019-02-04 Thread Alex via Digitalmars-d-learn
On Monday, 4 February 2019 at 10:36:49 UTC, Ron Tarrant wrote: On Sunday, 3 February 2019 at 18:53:10 UTC, Jacob Carlborg wrote: You don't need to make it so complicated. Here's a simpler example: Excellent. Thank you. Simple is best. private __gshared auto instance_ = new DSingleton;

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 22:25:18 UTC, Dejan Lekic wrote: I strongly suggest you find the thread started by Andrej Mitrovic many years ago. He compared several implementations of (thread-safe) singletons. I it an extremely helpful stuff, IMHO. Thanks. I'll see if I can find it.

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 18:53:10 UTC, Jacob Carlborg wrote: You don't need to make it so complicated. Here's a simpler example: Excellent. Thank you. Simple is best. private __gshared auto instance_ = new DSingleton; My understanding is that in D, this line effectively says: the

Re: Singleton in Action?

2019-02-04 Thread Ron Tarrant via Digitalmars-d-learn
On Sunday, 3 February 2019 at 15:33:15 UTC, Russel Winder wrote: There is a lot of good stuff (both positive and negative) on Singleton here, but there is also a bit of prejudice and bigotry. Many of the links are worth looking through. https://stackoverflow.com/questions/137975/what-is-so-ba

Re: Singleton in Action?

2019-02-04 Thread bauss 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 fo

Re: How can I express the type of a function in D?

2019-02-04 Thread dnsmt via Digitalmars-d-learn
On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote: I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. Did you consider `core.demangle

Re: Singleton in Action?

2019-02-04 Thread Kagamin via Digitalmars-d-learn
On Sunday, 3 February 2019 at 14:42:13 UTC, Ron Tarrant wrote: This morning I was Googling "singleton replacement" and someone on another forum said Factory would do the job. Anyone have thoughts on that? It's usually replaced with inversion of control: the service instance is passed as an ar