Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 06:20:05 UTC, mikey wrote: On Sunday, 9 October 2016 at 14:06:42 UTC, Antonio Corbi wrote: 1. Inheritance with contracts is evaluated in a special way, 'in contracts' in the base and derived method (property) are or-ed, so if one of them passses, the contract is

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread Antonio Corbi via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 06:20:05 UTC, mikey wrote: On Sunday, 9 October 2016 at 14:06:42 UTC, Antonio Corbi wrote: 1. Inheritance with contracts is evaluated in a special way, 'in contracts' in the base and derived method (property) are or-ed, so if one of them passses, the contract is

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 09, 2016 14:06:42 Antonio Corbi via Digitalmars-d-learn wrote: > I think that the compiler assumes that its empty contract is always true. That's exactly what it does. Having no contract is considered to be equivalent to having an empty contract. So, because an empty contract w

Re: How to do "inheritance" in D structs

2016-10-12 Thread cym13 via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 02:33:20 UTC, lobo wrote: On Wednesday, 12 October 2016 at 02:18:47 UTC, TheFlyingFiddle wrote: On Wednesday, 12 October 2016 at 01:22:04 UTC, lobo wrote: Hi, I'm coming from C++ and wondered if the pattern below has an equivalent in D using structs. I could j

vibe.d HTMLLogger

2016-10-12 Thread Chris via Digitalmars-d-learn
Why does FileLogger work while HTMLLogger crashes on the same thing? I've had a look at the source code, but couldn't find anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` alike (haven't tested lower versions). [Test code] auto logLine = LogLine(); logLine.level = LogLevel.info; /

Anonymous class

2016-10-12 Thread tcak via Digitalmars-d-learn
I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */ } }); I want to do this without making the things any comp

Re: Anonymous class

2016-10-12 Thread tcak via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 11:56:21 UTC, tcak wrote: I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */

Re: Anonymous class

2016-10-12 Thread ag0aep6g via Digitalmars-d-learn
On 10/12/2016 01:56 PM, tcak wrote: I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */ } }); runIt(new class

Re: Anonymous class

2016-10-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 11:56:21 UTC, tcak wrote: I feel like I remember that this was added to D a while ago It has been there since the beginning, more or less, as long as I can remember.

Re: weighted round robin

2016-10-12 Thread Erikvv via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 06:28:10 UTC, vino wrote: On Monday, 10 October 2016 at 09:18:16 UTC, Marc Schütz wrote: [...] Hi Marc, Thank you, I have made a small update as the Server Array is fixed length and the Socket array would be dynamic so made the below changes as now it is

Re: vibe.d HTMLLogger

2016-10-12 Thread Chris via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 11:54:14 UTC, Chris wrote: Why does FileLogger work while HTMLLogger crashes on the same thing? I've had a look at the source code, but couldn't find anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` alike (haven't tested lower versions). [Test code

Re: vibe.d HTMLLogger

2016-10-12 Thread Chris via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 14:19:36 UTC, Chris wrote: The answer is that `HTMLLogger` needs to be given the time in the `LogLine` struct, else it fails. The time stamp is not auto generated. I completely overlooked that. Here's the culprit: cf. m_logFile.writef(`%s`, msg.time.toISOE

Re: Determining if a class has a template function

2016-10-12 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 20:17:19 UTC, Straivers wrote: I have a class T with a templated function foo(string name)(int, int, float) that will be mixed in via template, and I want to determine if that class has mixed it in such that foo(name = "bar"). How could I go about this? Thanks.

Re: Determining if a class has a template function

2016-10-12 Thread Meta via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 16:29:22 UTC, Basile B. wrote: On Tuesday, 11 October 2016 at 20:17:19 UTC, Straivers wrote: I have a class T with a templated function foo(string name)(int, int, float) that will be mixed in via template, and I want to determine if that class has mixed it in su

Re: Determining if a class has a template function

2016-10-12 Thread Meta via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 16:57:50 UTC, Meta wrote: //A template function's .stringof is of the format name>()() //so match on the number of brackets to determine whether it's a template function or not enum isTemplateFunction = __traits(isTemplate, f) && fst

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread mikey via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 08:36:43 UTC, Jonathan M Davis wrote: That's exactly what it does. Having no contract is considered to be equivalent to having an empty contract. So, because an empty contract will never fail, not having an in contract in the base class (or interface) function i

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread mikey via Digitalmars-d-learn
Also, accepting that "in" contracts should be "or"ed, interfaces still seem broken to me: import std.exception; interface Widthy { @property inout(int) width() inout; @property void width(int width) in { enforce(width < 0); } } class Test : Widthy { private:

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread mikey via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 20:49:40 UTC, mikey wrote: @property void width(int width) in { enforce(width < 0); } Arg! Stupid, I switched those around to enforces at the last minute, the sign should have been the other way round! Anyway the output is the same either way.

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread ag0aep6g via Digitalmars-d-learn
On 10/12/2016 10:40 PM, mikey wrote: import std.exception; class Worker { private: uint _wage = 10_000; public: @property uint wage() { return _wage; } @property void wage(uint wage) in { enforce(wage >= 10_000 && wage <= 1_000_000_000

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread ag0aep6g via Digitalmars-d-learn
On 10/12/2016 10:49 PM, mikey wrote: import std.exception; interface Widthy { @property inout(int) width() inout; @property void width(int width) in { enforce(width < 0); } } class Test : Widthy { private: int _w; public: @property inout(i

Re: Continued looking at properties in D - interfaces and constraints

2016-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 12, 2016 20:40:57 mikey via Digitalmars-d-learn wrote: > OK I'm somewhat struggling with this concept. It is a bit weird. But consider class A { ... auto foo(int i) in { assert(i < 10); } out(r) { assert(r > 20); } body {...} ... } class B : A {

overriding alias symbols

2016-10-12 Thread Superstar64 via Digitalmars-d-learn
I'm trying to use mixin templetes to provide generic default implementations. Something like this: --- abstract class MyAbstractClass { void myAbstractMethod(); } mixin template defaultImplentation(alias Method, T...) { override void Method() { } } class MyClass : MyAbstractClas

Re: opIndexDispatch?

2016-10-12 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 10 October 2016 at 19:16:06 UTC, Jonathan M Davis wrote: On Monday, October 10, 2016 19:01:19 Yuxuan Shui via Digitalmars-d-learn wrote: Hi, Why is there no opIndexDispatch for overloading a[x].func() ? There's opIndex for overloading a[x], and then you can call a function on the

Re: overriding alias symbols

2016-10-12 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 22:14:32 UTC, Superstar64 wrote: I'm trying to use mixin templetes to provide generic default implementations. Something like this: --- abstract class MyAbstractClass { void myAbstractMethod(); } mixin template defaultImplentation(alias Method, T...) { o

Re: overriding alias symbols

2016-10-12 Thread Superstar64 via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 22:46:14 UTC, Stefan Koch wrote: override void mixin (__traits(identifier, Method)) ... ? Doesn't work: test.d(8): Error: no identifier for declarator void test.d(9): Error: found '{' when expecting ')' test.d(10): Error: found '}' when expecting ';' I could mak

Re: opIndexDispatch?

2016-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 12, 2016 22:45:28 Yuxuan Shui via Digitalmars-d-learn wrote: > On Monday, 10 October 2016 at 19:16:06 UTC, Jonathan M Davis > > wrote: > > On Monday, October 10, 2016 19:01:19 Yuxuan Shui via > > > > Digitalmars-d-learn wrote: > >> Hi, > >> > >> Why is there no opIndexDispatc

Re: overriding alias symbols

2016-10-12 Thread Superstar64 via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 22:14:32 UTC, Superstar64 wrote: ... Nevermind I just realized I can do this: --- abstract class MyAbstractClass { void myAbstractMethod(); } void defaultImplentation(T...) { } class MyClass : MyAbstractClass { override void myAbstractMethod() {

Re: opIndexDispatch?

2016-10-12 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 23:14:26 UTC, Jonathan M Davis wrote: opIndexUnary, opIndexAssign, and opIndexOpAssign exist to make it possible to do some basic operations on the result of foo[bar] without having to have opIndex return by ref, but assuming that you can return by ref, all of t

Re: opIndexDispatch?

2016-10-12 Thread Ali Çehreli via Digitalmars-d-learn
On 10/10/2016 12:01 PM, Yuxuan Shui wrote: Hi, Why is there no opIndexDispatch for overloading a[x].func() ? I could not understand the question fully but would using an element proxy work? import std.stdio; struct ElementProxy { size_t index; void opDispatch(string name, Args...)

Re: Rust-like collect in D

2016-10-12 Thread Andrei Alexandrescu via Digitalmars-d-learn
On 10/06/2016 10:32 AM, Nordlöw wrote: Is there a concept in D similar to Rust's `collect`: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect That's "make" in std.container. Is that what you're looking for? As an aside, "collect" is an awful abbreviation of "collection". -

Re: Rust-like collect in D

2016-10-12 Thread Meta via Digitalmars-d-learn
On Thursday, 13 October 2016 at 01:15:22 UTC, Andrei Alexandrescu wrote: On 10/06/2016 10:32 AM, Nordlöw wrote: Is there a concept in D similar to Rust's `collect`: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect That's "make" in std.container. Is that what you're lookin

Re: Rust-like collect in D

2016-10-12 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2016-10-13 at 02:33 +, Meta via Digitalmars-d-learn wrote: > On Thursday, 13 October 2016 at 01:15:22 UTC, Andrei Alexandrescu  > wrote: > > On 10/06/2016 10:32 AM, Nordlöw wrote: > > > Is there a concept in D similar to Rust's `collect`: > > > > > > https://doc.rust-lang.org/std/iter/

Re: Rust-like collect in D

2016-10-12 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2016-10-12 at 21:15 -0400, Andrei Alexandrescu via Digitalmars- d-learn wrote: > On 10/06/2016 10:32 AM, Nordlöw wrote: > > Is there a concept in D similar to Rust's `collect`: > > > > https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.colle > > ct > > That's "make" in std.cont