Re: Surprising interaction of tuples and slicing

2020-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/20 8:33 AM, Ben Jones wrote:> I was doing some metaprogramming where I wanted to make a slice of a type: [...] > alias Ts = AliasSeq!int; > pragma(msg, Ts); > alias Tsa = Ts[]; > pragma(msg, Tsa); > //prints (int), (int) > > which confused me until I realized that the [] was slicing the

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: On 5/7/20 5:22 AM, learner wrote: [...] Because VariantN (the base of Algebraic) can literally hold anything, it cannot be pure, @safe, nothrow, @nogc. As others have recommended, I suggest using TaggedAlgebraic. I

Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 17:59:30 UTC, Paul Backus wrote: On Thursday, 7 May 2020 at 15:00:18 UTC, jmh530 wrote: Does foo!y0(rt) generate the same code as foo(rt, y0)? How is the code generated by foo(rt, x0) different from foo(rt,y0)? You can look at the generated code using the Compiler

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 05:34:21PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > Compared with LDC and GDC, DMD has a poor optimizer, [...] DMD's optimizer is the whipping boy around here, but to be fair, it is poor only when it comes to aggrssive inlining and optimizing loops. Other

Re: CTFE and Static If Question

2020-05-07 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:00:18 UTC, jmh530 wrote: Does foo!y0(rt) generate the same code as foo(rt, y0)? How is the code generated by foo(rt, x0) different from foo(rt,y0)? You can look at the generated code using the Compiler Explorer at d.godbolt.org. Here's a link to your example,

Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:34:21 UTC, ag0aep6g wrote: [snip] The `static if` is guaranteed to be evaluated during compilation. That means, `foo!y0` effectively becomes this: auto foo(int rt) { return rt + 1; } There is no such guarantee for `foo(rt, y0)`. It doesn't matter that y0

Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:29:01 UTC, H. S. Teoh wrote: [snip] You explained things very well, thanks.

Re: Error running concurrent process and storing results in array

2020-05-07 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:41:12 UTC, drug wrote: 07.05.2020 17:49, data pulverizer пишет: On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D:  ~ 1.5 seconds After running the Julia code by the Julia

Re: variant visit not pure?

2020-05-07 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:36:36 UTC, Ben Jones wrote: On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: As others have recommended, I suggest using TaggedAlgebraic. I recently have been using it to create an algebraic type to hold a MYSQL value, so I can migrate the

Re: Error running concurrent process and storing results in array

2020-05-07 Thread drug via Digitalmars-d-learn
07.05.2020 17:49, data pulverizer пишет: On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D:  ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so

Re: variant visit not pure?

2020-05-07 Thread Ben Jones via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: As others have recommended, I suggest using TaggedAlgebraic. I recently have been using it to create an algebraic type to hold a MYSQL value, so I can migrate the mysql-native library to be @safe (mysql-native currently

Re: CTFE and Static If Question

2020-05-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.05.20 17:00, jmh530 wrote: Does foo!y0(rt) generate the same code as foo(rt, y0)? How is the code generated by foo(rt, x0) different from foo(rt,y0)? auto foo(bool rtct)(int rt) {     static if (rtct)     return rt + 1;     else     return rt; } auto foo(int rt, bool rtct) {

Surprising interaction of tuples and slicing

2020-05-07 Thread Ben Jones via Digitalmars-d-learn
I was doing some metaprogramming where I wanted to make a slice of a type: alias Tbasic = int; pragma(msg, Tbasic); alias Tbasica = Tbasic[]; pragma(msg, Tbasica); //prints int, int[] And things worked fine until I attempted the same thing on what happened to be a tuple of 1 element:

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 03:00:18PM +, jmh530 via Digitalmars-d-learn wrote: > I am curious how ctfe and static ifs interact. Then you should find this article helpful: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time > In particular, if an enum bool passed as a

CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
I am curious how ctfe and static ifs interact. In particular, if an enum bool passed as a template parameter or run-time one will turn an if statement into something like a static if statement (perhaps after the compiler optimizes other code away). In the code below, I am a function that takes

Re: variant visit not pure?

2020-05-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/7/20 5:22 AM, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure {     Algebraic!(int, string) alg;     visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function

Re: Error running concurrent process and storing results in array

2020-05-07 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D: ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so far is using simd maybe we can get even

Re: variant visit not pure?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 13:17:21 UTC, learner wrote: I've find this: https://issues.dlang.org/show_bug.cgi?id=16662 Hmm, that explains why it can't infer attributes. An unlimited variant could contain an object, and using it might or might not be . Of course, it could still infer the

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:41:01 UTC, Simen Kjærås wrote: On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) =>

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:51:27 UTC, Simen Kjærås wrote: If I understand correctly, you want to measure how many cycles pass, rather than clock time? Something like that. Well, I would also like to eliminate differences based on different memory caches between machines. In addition,

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 11:06:17 UTC, Dennis wrote: You can make a reference program that you use to get a measure for how fast the computer is that you run the benchmark on. Then you can use that to scale your actual benchmark results. When testing regressions there's a fairly obvious

Re: Get months / years between two dates.

2020-05-07 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 19:51:01 UTC, bauss wrote: How do you exactly do that? Like if I have two dates as std.datetime.DateTime How will I get the months or years between the two dates? I was surprised to learn that Duration does not support them and only has weeks, days etc. but not

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Dennis via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:21:07 UTC, Dukc wrote: Is there some way to measure the performance of a function so that the results will be same in different computers (all x86, but otherwise different processors)? I'm thinking of making a test suite that could find performance regressions

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:21:07 UTC, Dukc wrote: Is there some way to measure the performance of a function so that the results will be same in different computers (all x86, but otherwise different processors)? I'm thinking of making a test suite that could find performance regressions

Re: variant visit not pure?

2020-05-07 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function

Re: variant visit not pure?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? I think `variant` will not infer any trributes. I'm not sure why. It could be some language limitation (that's the reason why `std.range.enumerate` does not

Is there a way to benchmark/profile portably?

2020-05-07 Thread Dukc via Digitalmars-d-learn
Is there some way to measure the performance of a function so that the results will be same in different computers (all x86, but otherwise different processors)? I'm thinking of making a test suite that could find performance regressions automatically. I figured out Bochs[1] could be used for

variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function test.visit!(VariantN!(16LU, int, string)).visit ``` Thank

Re: How to port C++ std::is_reference to D ?

2020-05-07 Thread wjoe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 16:01:37 UTC, Paul Backus wrote: On Wednesday, 6 May 2020 at 09:40:47 UTC, wjoe wrote: yes, I did read the spec. I read the language spec on traits as well as std.traits docs as well as searching the internet for a solution since day before yesterday. But I couldn't