Re: Overloading for lvalue and rvalue.

2017-06-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 12, 2017 20:40:52 Balagopal Komarath via Digitalmars-d-learn wrote: > Is there a way to avoid the following combinatorial explosion of > overloaded functions when overloading for lvalue and rvalue > arguments? The following may be a bad example because int is > cheap to copy. So as

Overloading for lvalue and rvalue.

2017-06-12 Thread Balagopal Komarath via Digitalmars-d-learn
Is there a way to avoid the following combinatorial explosion of overloaded functions when overloading for lvalue and rvalue arguments? The following may be a bad example because int is cheap to copy. So assume a large datatype instead of int. import std.stdio; void foo(in ref int a, in ref i

Re: Generic operator overloading for immutable types?

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 01:08:13PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 06/12/2017 01:03 PM, Gary Willoughby wrote: > > On Monday, 12 June 2017 at 19:36:52 UTC, H. S. Teoh wrote: > > >> public inout Rational opBinary(string op)(inout Rational rhs) > > > Quick question abou

Re: Generic operator overloading for immutable types?

2017-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2017 01:03 PM, Gary Willoughby wrote: > On Monday, 12 June 2017 at 19:36:52 UTC, H. S. Teoh wrote: >> public inout Rational opBinary(string op)(inout Rational rhs) > Quick question about the signature, if I change it to (note the parens): > >public inout(Rational) opBinary(stri

Re: Generic operator overloading for immutable types?

2017-06-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 12 June 2017 at 19:36:52 UTC, H. S. Teoh wrote: On Mon, Jun 12, 2017 at 07:38:44PM +, Gary Willoughby via Digitalmars-d-learn wrote: In the following code is there any way to make the `opBinary` method generic to be able to accept immutable as well as a standard type? The code cu

Re: Generic operator overloading for immutable types?

2017-06-12 Thread arturg via Digitalmars-d-learn
On Monday, 12 June 2017 at 19:51:37 UTC, Gary Willoughby wrote: I don't know how H. S. Teoh managed to answer 'before' I posted but thanks guys! :) might be a bug, happened here http://forum.dlang.org/post/ohbr5l$2mng$1...@digitalmars.com also.

Re: Generic operator overloading for immutable types?

2017-06-12 Thread Gary Willoughby via Digitalmars-d-learn
I don't know how H. S. Teoh managed to answer 'before' I posted but thanks guys! :)

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
Arafel wrote: I actually found a workaround for the original issue: yeah, sorry for not proposing a workaround: i thought that you already did it, and now you're just interested why the original code doesn't work. ;-) i think that this is a bug (or, rather, unimplemented feature).

Re: Generic operator overloading for immutable types?

2017-06-12 Thread ketmar via Digitalmars-d-learn
Gary Willoughby wrote: In the following code is there any way to make the `opBinary` method generic to be able to accept immutable as well as a standard type? The code currently passes the unit test but I wonder if I could get rid of the duplication to overload the operator? I'm failing badly.

Re: Generic operator overloading for immutable types?

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 07:38:44PM +, Gary Willoughby via Digitalmars-d-learn wrote: > In the following code is there any way to make the `opBinary` method > generic to be able to accept immutable as well as a standard type? The > code currently passes the unit test but I wonder if I could get

Re: Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
On Monday, 12 June 2017 at 19:23:10 UTC, ketmar wrote: p.s.: while i understand the technical reason for second error message, it is still random and confusing. I think the reason for the typeof problem is that it works with expressions, not with types (so, typeof (int) is also not valid), an

Generic operator overloading for immutable types?

2017-06-12 Thread Gary Willoughby via Digitalmars-d-learn
In the following code is there any way to make the `opBinary` method generic to be able to accept immutable as well as a standard type? The code currently passes the unit test but I wonder if I could get rid of the duplication to overload the operator? I'm failing badly. import std.stdio; s

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
p.s.: while i understand the technical reason for second error message, it is still random and confusing.

Re: Weird template instantiation problem

2017-06-12 Thread ketmar via Digitalmars-d-learn
more funny compiler messages: alias xx = size_t function (int[]); struct S1(T, typeof(xx) X) {} void main() { S1!(int, defaultChooser!int) s; } Error: type uint function(int[]) is not an expression but: struct S2(T, typeof(defaultChooser!T) cho

Re: O(1) sum

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 06:16:06PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Monday, 12 June 2017 at 06:15:07 UTC, Biotronic wrote: [...] > > On a multi-core system we can do better: > > > > auto nums = iota(10_000_000.0f); > > auto sum = taskPool.reduce!"a + b"(nums); > > > > Given

Re: O(1) sum

2017-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/11/2017 06:02 PM, helxi wrote: Is it possible to sum an array in O(1)? It's possible to maintain the sum as elements are added and removed. Then, accessing it would be O(1). Ali

Re: O(1) sum

2017-06-12 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 12 June 2017 at 06:15:07 UTC, Biotronic wrote: On Monday, 12 June 2017 at 01:36:04 UTC, Stefan Koch wrote: On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the element

Re: Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
On 06/12/2017 05:31 PM, Arafel wrote: Hi, I've found a strange problem, and I'm not sure if it's a bug. To give a bit of background, I'm implementing a multi-threaded producer-consumer where the next work item to be picked depends not only on the "waiting queue", but also on what else is bein

Weird template instantiation problem

2017-06-12 Thread Arafel via Digitalmars-d-learn
Hi, I've found a strange problem, and I'm not sure if it's a bug. To give a bit of background, I'm implementing a multi-threaded producer-consumer where the next work item to be picked depends not only on the "waiting queue", but also on what else is being run (and potentially where) at the s

Trouble with regex backreferencing

2017-06-12 Thread Murp via Digitalmars-d-learn
I was working around with regex trying to match certain patterns of repeating patterns before and after a space and I came across some unexpected behavior. writeln("ABC ABC CBA".replaceAll(regex(r"([A-Z]) ([A-Z])"), "D")); //ABDBDBA //Makes sense, replaces the 3 characters surroundi

Re: std.path.buildPath

2017-06-12 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2017-06-04 at 21:32 +0200, Jacob Carlborg via Digitalmars-d- learn wrote: > On 2017-06-04 19:05, Patrick Schluter wrote: > > > buildPath("/usr/bin", "/usr/bin/gcc") > > > > /usr/bin/usr/bin/gcc is obviously wrong. > > Says who? It might be exactly what I want. The case that came up is >

Re: std.path.buildPath

2017-06-12 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2017-06-11 at 13:21 +, Ryan Frame via Digitalmars-d-learn wrote: > On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote: > > On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via > > Digitalmars-d- learn wrote: > > > On 2017-06-04 07:44, Jesse Phillips wrote: > > > > > > > What