Re: opCmp with and without const

2019-12-05 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 December 2019 at 07:03:45 UTC, berni44 wrote: My real question is: Can this code duplication be avoided somehow? (I ask, because I've got a PR running, which increases the size of these functions and it doesn't feel good to have two long, almost identical functions.) You can use

opCmp with and without const

2019-12-05 Thread berni44 via Digitalmars-d-learn
In std.typecons, in Tuple there are two opCmp functions, that are almost identical; they only differ by one being const and the other not: int opCmp(R)(R rhs) if (areCompatibleTuples!(typeof(this), R, "<")) { static foreach (i; 0 .. Types.length)

Re: optional process

2019-12-05 Thread Taylor Hillegeist via Digitalmars-d-learn
On Friday, 6 December 2019 at 05:09:58 UTC, Paul Backus wrote: On Thursday, 5 December 2019 at 17:27:45 UTC, Taylor Hillegeist wrote: I agree with this. I wasn't clear enough in my question though. I was trying to distinguish between std.functional.compose and std.functional.pipe they look

Re: optional process

2019-12-05 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 5 December 2019 at 17:27:45 UTC, Taylor Hillegeist wrote: I agree with this. I wasn't clear enough in my question though. I was trying to distinguish between std.functional.compose and std.functional.pipe they look very the same. Pipe says it reverses functions order. Which

Split but keep one delimiter

2019-12-05 Thread Taylor Hillegeist via Digitalmars-d-learn
Learning all the ins and outs of the std library is fun. But there are soo many hidden gems that its hard to tell when to keep looking and when to just write something. I was working on a split function with some particulars: Split but keep exactly one delimiter at the beginning of each

Re: How can I make a program which uses all cores and 100% of cpu power?

2019-12-05 Thread Murilo via Digitalmars-d-learn
On Friday, 11 October 2019 at 06:18:03 UTC, Ali Çehreli wrote: Your threads must allocate as little memory as possible because memory allocation can trigger garbage collection and garbage collection stops all threads (except the one that's performing collection). We studied the effects of

Re: How can I make a program which uses all cores and 100% of cpu power?

2019-12-05 Thread Murilo via Digitalmars-d-learn
On Friday, 11 October 2019 at 06:57:46 UTC, Russel Winder wrote: A neural net is, at it's heart, a set of communicating nodes. This is as much an I/O bound model as it is compute bound one – nodes are generally waiting for input as much as they are computing a value. The obvious solution

Re: optional process

2019-12-05 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 5 December 2019 at 15:43:30 UTC, Paul Backus wrote: On Thursday, 5 December 2019 at 15:30:52 UTC, Taylor Hillegeist wrote: On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote: .pipe!((output) { if (sortOutput) return output.sort!("a < b"); else

Re: Strange casting error when using lamdas

2019-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/5/19 3:57 AM, Robert M. Münch wrote: On 2019-12-04 19:23:07 +, Steven Schveighoffer said: Is one a delegate and one a function pointer? This can easily happen for untyped lambdas. That's a very good point and hint. A function pointer will be 8LU and a delegate 16LU, right? This is

Re: optional process

2019-12-05 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 5 December 2019 at 15:30:52 UTC, Taylor Hillegeist wrote: On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote: .pipe!((output) { if (sortOutput) return output.sort!("a < b"); else return output; }) .writeln(); // maybe you meant

Re: optional process

2019-12-05 Thread Taylor Hillegeist via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote: .pipe!((output) { if (sortOutput) return output.sort!("a < b"); else return output; }) .writeln(); // maybe you meant each!writeln ? Why pipe as apposed to compose? Pipes functions in

Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-04 19:23:07 +, Steven Schveighoffer said: Is one a delegate and one a function pointer? This can easily happen for untyped lambdas. Not sure if the code-snippets already give an explanation but the differences I have are: 1. Working case template filter(alias pred) {

Re: Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?

2019-12-05 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote: Simple example: writeln("Hi\nHow are you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]); How to refer to this string in lastIndexOf() without create a variable? Thank you. .splitLines[0] already just produces "Hi", containing

Re: Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?

2019-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote: Simple example: writeln("Hi\nHow are you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]); How to refer to this string in lastIndexOf() without create a variable? Thank you. One solution: writeln( "Hello\nHow are

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 5 December 2019 at 12:00:23 UTC, Ola Fosheim Grøstad wrote: So basically, templated functions get flow-typing. But it is not reliable :-( struct node {int value; node* next;} node n0 = {1,null}; node mk_node1()(node* n){ node tmp = {2019, n}; return tmp; } node

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
So basically, templated functions get flow-typing. I guess that is a good reason to use templated functions more... What is the downside? E.g.: struct node {int value; node* next;} node mk_node2()(){ node tmp = {2019, null}; return tmp; } node mk_node(){ node tmp = {2019, null};

Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?

2019-12-05 Thread Marcone via Digitalmars-d-learn
Simple example: writeln("Hi\nHow are you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]); How to refer to this string in lastIndexOf() without create a variable? Thank you.

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 5 December 2019 at 10:41:24 UTC, Ola Fosheim Grøstad wrote: immutable x1 = mk!node1(); //succeeds? immutable y1 = mk_node1(); //fails Nevermind, seems like templated functions get stronger coercion, like: immutable y1 = cast(immutable)mk_node1(); (Also no need to

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
I also find the following behaviour a bit unclear: struct node0 {int value; node0* next;} struct node1 {int value; const(node1)* next;} struct node2 {int value; immutable(node0)* next;} T mk(T)(){ T tmp = {2019, null}; return tmp; } node1 mk_node1(){ node1 tmp = {2019, null};

Re: Strange casting error when using lamdas

2019-12-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-12-04 19:23:07 +, Steven Schveighoffer said: Is one a delegate and one a function pointer? This can easily happen for untyped lambdas. That's a very good point and hint. A function pointer will be 8LU and a delegate 16LU, right? This is a strong argument that this is really the

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 23:27:49 UTC, Steven Schveighoffer wrote: void foo(alias f)() { alias ConstType = const(typeof(f())); pragma(msg, ConstType); } I expressed myself poorly, what I am interested in is this: struct node1 {int value; const(node1)* next;} struct node2 {int

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
I haven't used const much in the past because I got burned on transitive const, so I managed to confuse myself. I am not really interested in const/immutabel references here, only values. Seems like there is no reason to ever use const values, except when the value may contain a pointer to

Re: const and immutable values, D vs C++?

2019-12-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
I haven't used const much in the past because I got burned on transitive const, so I managed to confuse myself. I am not really interested in const/immutabel references here, but values. Seems like there is no reason to ever use const values, except when they contain a pointer to something