Re: Solving the impossible?

2018-08-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 20:37:05 UTC, Everlast wrote: Also, the biggest complaint is that when we use [] attached to a type it has a specific meaning as "an array of". e.g., int[] means an array of int's. But int[] a... then changes as we don't have an array of int's any more but

Re: Can you get typeof(this) in a mixin template - trying to mimic a Kotlin feature here.

2018-08-28 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 20:39:16 UTC, aliak wrote: Hi, I'm trying to do something similar to what Kotlin allows with assigning to member variables from a map. The syntax is very readable and looks like: class User(val map: Map) { val name: String by map val age: Int by map

Re: Solving the impossible?

2018-08-28 Thread Everlast via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 19:40:36 UTC, Paul Backus wrote: On Tuesday, 28 August 2018 at 19:09:38 UTC, Everlast wrote: Yeah, I see the link paul posted. The actual syntax seems a bit strange to me... We don't do A[] a So it is not "logical". foo(A...)(A a) but if A is a specific

Can you get typeof(this) in a mixin template - trying to mimic a Kotlin feature here.

2018-08-28 Thread aliak via Digitalmars-d-learn
Hi, I'm trying to do something similar to what Kotlin allows with assigning to member variables from a map. The syntax is very readable and looks like: class User(val map: Map) { val name: String by map val age: Int by map } So I'm trying to do something similar in D: mixin

Re: Solving the impossible?

2018-08-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 19:09:38 UTC, Everlast wrote: Yeah, I see the link paul posted. The actual syntax seems a bit strange to me... We don't do A[] a So it is not "logical". foo(A...)(A a) but if A is a specific type we must do foo(int[] a ...) The actual syntax then looks

Re: Solving the impossible?

2018-08-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 19:09:38 UTC, Everlast wrote: On Tuesday, 28 August 2018 at 12:00:50 UTC, bauss wrote: On Sunday, 26 August 2018 at 02:26:58 UTC, Everlast wrote: in fact, I'd rather see void print(T)(T t, int... a) You were actually close. void print(T)(T t, int[] a ...);

Re: Solving the impossible?

2018-08-28 Thread Everlast via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 12:00:50 UTC, bauss wrote: On Sunday, 26 August 2018 at 02:26:58 UTC, Everlast wrote: in fact, I'd rather see void print(T)(T t, int... a) You were actually close. void print(T)(T t, int[] a ...); Yeah, I see the link paul posted. The actual syntax seems a

Re: Null-Coalescing Operator and Extensions

2018-08-28 Thread aliak via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 13:27:28 UTC, Simen Kjærås wrote: Now, as has been pointed out, that only work for null-coalescing, not null-propagation. It seems writers of Optional, Variant, SumType, and so on, have decided not to support this out of the box, but rather wrap it separately,

Weird (buggy) behaviour of "protected static" in classes

2018-08-28 Thread Arafel via Digitalmars-d-learn
Hi all, I have noticed that "protected static" doesn't work currently with classes. In my case, I wanted to use "static immutable", but I have tried regular static members and methods, and the same issue happens. However, the puzzling part is that protected enums (which are a valid

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread Andrey via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 13:05:15 UTC, bauss wrote: I'm not sure if there is a better way, but isInstanceOf (std.traits) seems to work with a static foreach and a static if. template Qwerty(Values...) { static foreach (value; Values) { static if (!isInstanceOf!(Qaz,

Re: Null-Coalescing Operator and Extensions

2018-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 27 August 2018 at 14:59:20 UTC, SG wrote: On Monday, 27 August 2018 at 07:59:17 UTC, Simen Kjærås wrote: That's the null propagation operator (?.). What SG asked for is the null-coalescing operator (??). Of course, this can also be implemented in D (albeit with a slight more

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread vit via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote: Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Values" pack must be a "Qaz" template. I don't care about

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 13:05:15 UTC, bauss wrote: On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote: Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote: Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Values" pack must be a "Qaz" template. I don't care about

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread vit via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote: Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Values" pack must be a "Qaz" template. I don't care about

Re: Pass Socket to new thread

2018-08-28 Thread Ivo via Digitalmars-d-learn
Thanks for all your answers. I'll have a look at the design and use casting if necessary.

Create constraint for each parameter in template arg pack

2018-08-28 Thread Andrey via Digitalmars-d-learn
Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Values" pack must be a "Qaz" template. I don't care about values of "type" or "Data" in "Qaz". How to do it in D?

Re: Solving the impossible?

2018-08-28 Thread bauss via Digitalmars-d-learn
On Sunday, 26 August 2018 at 02:26:58 UTC, Everlast wrote: in fact, I'd rather see void print(T)(T t, int... a) You were actually close. void print(T)(T t, int[] a ...);

Re: Pass Socket to new thread

2018-08-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 10:48:20 UTC, Ivo wrote: I'm writing a basic server program and I want to handle each connection received in a new thread. So here is the code I'm trying to produce: while(true) { auto client = socket.accept(); spawn( , client); } void

Re: Pass Socket to new thread

2018-08-28 Thread Kagamin via Digitalmars-d-learn
while(true) { auto client = socket.accept(); spawn(, cast(shared)client); } void handleConnection(shared Socket sclient) { Socket client=cast()sclient; //do stuff like receive and send }

Re: "The D Way" to run a sequence of executables?

2018-08-28 Thread Kagamin via Digitalmars-d-learn
Maybe http://libpipeline.nongnu.org/ can be an inspiration.

Pass Socket to new thread

2018-08-28 Thread Ivo via Digitalmars-d-learn
I'm writing a basic server program and I want to handle each connection received in a new thread. So here is the code I'm trying to produce: while(true) { auto client = socket.accept(); spawn( , client); } void handleConnection(Socket client) { //do stuff like receive and send }

Re: Null-Coalescing Operator and Extensions

2018-08-28 Thread Kagamin via Digitalmars-d-learn
On Saturday, 25 August 2018 at 13:33:58 UTC, SG wrote: 1) I program in C# and I'm wondering if there is something like ?? (Null-Coalescing Operator) in D? (I remember some proposals in the past). Another example: https://github.com/aliak00/optional/blob/master/source/optional/optional.d#L340

Re: tupleof function parameters?

2018-08-28 Thread aliak via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:20:37 UTC, Sebastiaan Koppe wrote: On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: The goal is to write the argument list once and use it to create both the function and the Tuple alias. That way I could create a large number of these function

Re: tupleof function parameters?

2018-08-28 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:20:37 UTC, Sebastiaan Koppe wrote: On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: The goal is to write the argument list once and use it to create both the function and the Tuple alias. That way I could create a large number of these function

Re: Is there a simple way to check if value is null for every case?

2018-08-28 Thread aliak via Digitalmars-d-learn
On Monday, 27 August 2018 at 21:48:04 UTC, Alex wrote: On Monday, 27 August 2018 at 19:36:29 UTC, aliak wrote: Then Nullable!(int*) would be the same as int*. Or even better maybe is to give a compiler error when you try and stuff a nullable type inside a Nullable. Because ... why? Isn't

Re: tupleof function parameters?

2018-08-28 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: The goal is to write the argument list once and use it to create both the function and the Tuple alias. That way I could create a large number of these function / arglist tuple pairs with less brittleness. --Jon I would

Re: tupleof function parameters?

2018-08-28 Thread Alex via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: I'd like to create a Tuple alias representing a function's parameter list. Is there a way to do this? [...] Are you aware of https://dlang.org/phobos/std_traits.html#Parameters

tupleof function parameters?

2018-08-28 Thread Jon Degenhardt via Digitalmars-d-learn
I'd like to create a Tuple alias representing a function's parameter list. Is there a way to do this? Here's an example creating a Tuple alias for a function's parameters by hand: import std.typecons: Tuple; bool fn(string op, int v1, int v2) { switch (op) {