Re: Null-Coalescing Operator and Extensions

2018-08-27 Thread Basile B. 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: Is there a simple way to check if value is null for every case?

2018-08-27 Thread Alex via Digitalmars-d-learn
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 it arguable, whether this is desired? I mean, in the

Re: Can passing an address of this to a non-copyable object be made trusted? - i.e. can I disable moving?

2018-08-27 Thread aliak via Digitalmars-d-learn
On Monday, 27 August 2018 at 00:15:18 UTC, Jonathan M Davis wrote: On Sunday, August 26, 2018 5:10:29 PM MDT Nicholas Wilson via So, soon™? Bah humbug. Was afraid of this :p Yeah. Hopefully, we're able to disable moving at some point in the near future. However, right now, it's definitely

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

2018-08-27 Thread aliak via Digitalmars-d-learn
On Monday, 27 August 2018 at 14:11:32 UTC, SG wrote: On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. The big difference is that in there I could do: int? i = null; string j = null; var

Re: How to pass alias as template parameter?

2018-08-27 Thread Everlast via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:50:01 UTC, Andrey wrote: Hello, This code doesn't compile: --- import std.meta; import std.stdio; enum Option : string { First = "-first" , Second = "-second", Qwerty = "-qwerty" }

Re: How to pass alias as template parameter?

2018-08-27 Thread Paul Backus via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:50:01 UTC, Andrey wrote: alias Pair(alias key, alias value) = AliasSeq!(key, value); alias Pairs = AliasSeq!(Pair!(Option.First, handler!(Option.First)), Pair!(Option.Second, handler!(Option.Second)), handler); You can't nest AliasSeqs. If you examine Pairs

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

2018-08-27 Thread Jacob Shtokolov via Digitalmars-d-learn
On Monday, 27 August 2018 at 14:11:32 UTC, SG wrote: On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. Shouldn't it be in the standard library? I think it's worth it to create a feature request

the "from" template and parameterized functions

2018-08-27 Thread aliak via Digitalmars-d-learn
I can't get the from template [0] to work in the following situation, is it possible? --- module m; import std.stdio; package template from(string moduleName) { mixin("import from = " ~ moduleName ~ ";"); } version(works) { struct S {} void t(from!"m".S param) {} auto a =

Re: Null-Coalescing Operator and Extensions

2018-08-27 Thread SG via Digitalmars-d-learn
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 horrible syntax): Exactly, and I know it is an example, but

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

2018-08-27 Thread SG via Digitalmars-d-learn
On Monday, 27 August 2018 at 13:02:28 UTC, rikki cattermole wrote: So Nullable in D and C# is basically the same except C#'s has language support. The big difference is that in there I could do: int? i = null; string j = null; var k = null; and test all like: i == null; j

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

2018-08-27 Thread vit via Digitalmars-d-learn
On Monday, 27 August 2018 at 12:54:59 UTC, SG wrote: On Monday, 27 August 2018 at 03:21:04 UTC, rikki cattermole wrote: Templates make it the easiest way, since common patterns, like arrays, classes and pointers have the exact same null check syntax. I see. That code is only for classes. C#

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

2018-08-27 Thread rikki cattermole via Digitalmars-d-learn
On 28/08/2018 12:54 AM, SG wrote: The same thing for struct in C# Struct S{    public int? i; } S.i == null; // This works nicely. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/index So Nullable in D and C# is basically the same except C#'s has language

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

2018-08-27 Thread SG via Digitalmars-d-learn
On Monday, 27 August 2018 at 03:21:04 UTC, rikki cattermole wrote: Templates make it the easiest way, since common patterns, like arrays, classes and pointers have the exact same null check syntax. I see. That code is only for classes. C# also has structs which are a value type. Which it

Re: How to use math functions in dcompute?

2018-08-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:57:18 UTC, Sobaya wrote: On Monday, 27 August 2018 at 09:41:34 UTC, 9il wrote: On Monday, 27 August 2018 at 08:25:14 UTC, Sobaya wrote: I'm using dcompute(https://github.com/libmir/dcompute). In the development, I have got to use math functions such as sqrt in

Re: How to mixin repeated text?

2018-08-27 Thread Andrey via Digitalmars-d-learn
On Monday, 27 August 2018 at 11:56:08 UTC, Kamil Koczurek wrote: Mixins seem to be an overkill here. Maybe something like this would suffice: data[index + 1 .. index + 5].map!(k => k[0]).array == "" Here there is dynamic code, with memory allocs. I found solution:

Re: How to mixin repeated text?

2018-08-27 Thread Kamil Koczurek via Digitalmars-d-learn
On Monday, 27 August 2018 at 11:52:02 UTC, Andrey wrote: Hello again, I have this part of code: ... if(index + 3 >= data.length || data[index + 1][0] == '&' || data[index + 2][0] == '&' || data[index + 3][0] == '&' || data[index + 4][0] == '&') { writeln("Some text..."); } I don't want

How to mixin repeated text?

2018-08-27 Thread Andrey via Digitalmars-d-learn
Hello again, I have this part of code: ... if(index + 3 >= data.length || data[index + 1][0] == '&' || data[index + 2][0] == '&' || data[index + 3][0] == '&' || data[index + 4][0] == '&') { writeln("Some text..."); } I don't want to write manually these four "or" conditions because in

Re: How to use math functions in dcompute?

2018-08-27 Thread 9il via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:57:18 UTC, Sobaya wrote: On Monday, 27 August 2018 at 09:41:34 UTC, 9il wrote: On Monday, 27 August 2018 at 08:25:14 UTC, Sobaya wrote: I'm using dcompute(https://github.com/libmir/dcompute). In the development, I have got to use math functions such as sqrt in

Re: How to use math functions in dcompute?

2018-08-27 Thread Sobaya via Digitalmars-d-learn
On Monday, 27 August 2018 at 09:41:34 UTC, 9il wrote: On Monday, 27 August 2018 at 08:25:14 UTC, Sobaya wrote: I'm using dcompute(https://github.com/libmir/dcompute). In the development, I have got to use math functions such as sqrt in @compute function. But LDC says "can only call

How to pass alias as template parameter?

2018-08-27 Thread Andrey via Digitalmars-d-learn
Hello, This code doesn't compile: --- import std.meta; import std.stdio; enum Option : string { First = "-first" , Second = "-second", Qwerty = "-qwerty" } void handler(Option option)(string[] args, ref ushort

Re: How to use math functions in dcompute?

2018-08-27 Thread 9il via Digitalmars-d-learn
On Monday, 27 August 2018 at 08:25:14 UTC, Sobaya wrote: I'm using dcompute(https://github.com/libmir/dcompute). In the development, I have got to use math functions such as sqrt in @compute function. But LDC says "can only call functions from other @compute modules in @compute code", so

How to use math functions in dcompute?

2018-08-27 Thread Sobaya via Digitalmars-d-learn
I'm using dcompute(https://github.com/libmir/dcompute). In the development, I have got to use math functions such as sqrt in @compute function. But LDC says "can only call functions from other @compute modules in @compute code", so can't I call any math functions with dcompute? Is there

Re: Null-Coalescing Operator and Extensions

2018-08-27 Thread Basile B. via Digitalmars-d-learn
On Saturday, 25 August 2018 at 19:16:26 UTC, Jacob Carlborg wrote: On 2018-08-25 15:33, SG wrote: Hi, 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). Not in the language but it can be implemented

Re: Null-Coalescing Operator and Extensions

2018-08-27 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 25 August 2018 at 19:16:26 UTC, Jacob Carlborg wrote: On 2018-08-25 15:33, SG wrote: Hi, 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). Not in the language but it can be implemented