How can I induce implicit type convesion with alias this on calling template function?

2018-10-14 Thread Sobaya via Digitalmars-d-learn
void func(T : int)(T value) if (is(T == int)) { } struct S { int x; alias x this; } void main() { func(S()); // error } In above code, 'func' can accept only int as its argument type, so when 'S', which can be implicitly convertible into int, is passed on 'func', I expect S.x is

Re: Noob question about structs allocation

2018-10-14 Thread IM via Digitalmars-d-learn
On Monday, 15 October 2018 at 03:33:04 UTC, Basile B. wrote: On Monday, 15 October 2018 at 03:19:07 UTC, IM wrote: I probably used to know the answer to this question, but it's been a long time since I last used D, and I don't remember. Suppose we have: struct S { int num; } Would

Re: Noob question about structs allocation

2018-10-14 Thread Basile B. via Digitalmars-d-learn
On Monday, 15 October 2018 at 03:19:07 UTC, IM wrote: I probably used to know the answer to this question, but it's been a long time since I last used D, and I don't remember. Suppose we have: struct S { int num; } Would allocating an instance on the heap using: S* s = new S; use the GC,

Noob question about structs allocation

2018-10-14 Thread IM via Digitalmars-d-learn
I probably used to know the answer to this question, but it's been a long time since I last used D, and I don't remember. Suppose we have: struct S { int num; } Would allocating an instance on the heap using: S* s = new S; use the GC, or do we have to call destroy() or delete on s

Re: Help about Template and class inheritance

2018-10-14 Thread Heromyth via Digitalmars-d-learn
On Sunday, 14 October 2018 at 15:06:49 UTC, Basile B. wrote: The basic problem you're faced to here is that D class / interface member functions that are templatized are never virtual. I'm not sure if i understand well the JAVA pattern you try to reproduce but since D interfaces can be

Re: Is there an efficient byte buffer queue?

2018-10-14 Thread Guillaume Piolat via Digitalmars-d-learn
On Monday, 8 October 2018 at 09:39:55 UTC, John Burton wrote: I would do much better to maintain a fixed size buffer and maintain read and write positions etc. Perhaps https://github.com/AuburnSounds/Dplug/blob/master/core/dplug/core/ringbuf.d#L16

Re: Help about Template and class inheritance

2018-10-14 Thread Basile B. via Digitalmars-d-learn
On Sunday, 14 October 2018 at 13:21:00 UTC, Heromyth wrote: Here is a sample code ```d import std.stdio; class Future(T) { T result; this(T r) { this.result = r; } } interface IExecutorService { // Future!(T) submit(T)(T result); // can't be

Help about Template and class inheritance

2018-10-14 Thread Heromyth via Digitalmars-d-learn
Here is a sample code ```d import std.stdio; class Future(T) { T result; this(T r) { this.result = r; } } interface IExecutorService { // Future!(T) submit(T)(T result); // can't be implemented } abstract class ExecutorService :

Re: Is there an efficient byte buffer queue?

2018-10-14 Thread Heromyth via Digitalmars-d-learn
On Monday, 8 October 2018 at 09:39:55 UTC, John Burton wrote: My use case is sending data to a socket. We have ported some containers from JAVA. ByteBuffer is a basic container interface and widely used in JAVA. See also:

Re: custom sorting of lists ?

2018-10-14 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis wrote: Unless there's something about the implementation that's tied to the list itself, I would think that it would make more sense to make it a generic algorithm, then it will work with any non-random-access range, and it avoids

Re: std.regex is fat

2018-10-14 Thread Chris Katko via Digitalmars-d-learn
On Sunday, 14 October 2018 at 03:26:33 UTC, Adam D. Ruppe wrote: On Sunday, 14 October 2018 at 03:07:59 UTC, Chris Katko wrote: For comparison, I just tested and grep uses about 4 MB of RAM to run. Running and compiling are two entirely different things. Running the D regex code should be

Re: custom sorting of lists ?

2018-10-14 Thread Codifies via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis wrote: Unless there's something about the implementation that's tied to the list itself, I would think that it would make more sense to make it a generic algorithm, then it will work with any non-random-access range, and it avoids