proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
Hi everybody, first of all: this question is going to be unclear, because I'm lack of the "buzz word" I would like to ask about, sorry for this in advance. I try to describe the problem, where I stuck and hope somebody could think just a step further. Just a hint where to read about the

Bidirectional Filter

2015-11-03 Thread Nordlöw via Digitalmars-d-learn
Is there a reason why std.algorithm.iteration.filter() doesn't propagate bidirectional access?

Re: Bidirectional Filter

2015-11-03 Thread Jakob Ovrum via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 08:41:11 UTC, Nordlöw wrote: Is there a reason why std.algorithm.iteration.filter() doesn't propagate bidirectional access? http://dlang.org/phobos/std_algorithm_iteration.html#filterBidirectional

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 08:23:20 UTC, Ali Çehreli wrote: > "Programming in D" book (the revision of 2015-10-24) Oooh! That smells very fresh. :) :) > In my case, the container class can't become empty. Even if it contains > one single element, in this case the example should return

Re: proper range usage

2015-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/02/2015 11:59 PM, Alex wrote: > "Programming in D" book (the revision of 2015-10-24) Oooh! That smells very fresh. :) > In my case, the container class can't become empty. Even if it contains > one single element, in this case the example should return true for > begin == end, it is not

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
... and yes, each P's M's are meant to be the same, as the associated M's in the B's class to the P. If you understand, what I mean ;)

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 03, 2015 07:35:40 Nordlöw via Digitalmars-d-learn wrote: > On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis > wrote: > > You should pretty much never use __FILE__ or __LINE__ as > > template arguments unless you actually need to. The reason is > > that it will end

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx. for many of them it is as

Re: foreach loop

2015-11-03 Thread wobbles via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:10:43 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: [...] for many of them it is as simple as:

Re: foreach loop

2015-11-03 Thread wobbles via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:10:43 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:10:43 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote: On Tuesday, 3 November 2015 at 14:52:19 UTC, Adam D. Ruppe wrote: On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each

Re: foreach loop

2015-11-03 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote: writefln("Count is: %s", arr .filter!(a => a==true) .sum); // Note: std.algorithm.sum is the same as // std.algorithm.reduce!((a,b)=a+b); Shouldn't you be using walkLength instead of sum, since you are counting the left over

Re: foreach loop

2015-11-03 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 16:55:44 UTC, wobbles wrote: On Tuesday, 3 November 2015 at 15:42:16 UTC, Edwin van Leeuwen wrote: On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote: writefln("Count is: %s", arr .filter!(a => a==true) .sum); // Note: std.algorithm.sum is the same as

Re: Efficiency of immutable vs mutable

2015-11-03 Thread Andrew via Digitalmars-d-learn
This: On Tuesday, 3 November 2015 at 04:08:09 UTC, TheFlyingFiddle wrote: __gshared char[4] lookup = ['a', 't', 'g', 'c]; Has the same efficiency gain as immutable, so it looks like a thread-local vs global difference and the extra cost is going through the thread-local lookup. Thanks

Re: foreach loop

2015-11-03 Thread wobbles via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:42:16 UTC, Edwin van Leeuwen wrote: On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote: writefln("Count is: %s", arr .filter!(a => a==true) .sum); // Note: std.algorithm.sum is the same as // std.algorithm.reduce!((a,b)=a+b); Shouldn't you be

Re: good reasons not to use D?

2015-11-03 Thread DLearner via Digitalmars-d-learn
On Saturday, 31 October 2015 at 14:37:23 UTC, rumbu wrote: On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: I'm writing a talk for codemesh on the use of D in finance. Any other thoughts? For finance stuff - missing a floating point decimal data type. Things like 1.1 + 2.2 =

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 22:36:21 UTC, Ali Çehreli wrote: That's fine. D's slices do that all the time: arr[0..3] and arr[3..$] seem to share index 3 but it is not the case: The first slice does not use it but the second one does. Ok... great! This is what I worried about... Aside: If

Re: good reasons not to use D?

2015-11-03 Thread steven kladitis via Digitalmars-d-learn
On Monday, 2 November 2015 at 17:09:41 UTC, Laeeth Isharc wrote: On Saturday, 31 October 2015 at 16:06:47 UTC, Russel Winder wrote: On Sat, 2015-10-31 at 15:41 +, tcak via Digitalmars-d-learn wrote: [...] In that std.bigint.BigInt provides the accuracy, yes it does suffice. But it is

Re: good reasons not to use D?

2015-11-03 Thread Chris via Digitalmars-d-learn
On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: Interesting. Two points suggest that you should use D only for serious programming: "cases where you want to write quick one-off scripts that need to use a bunch of different libraries not yet available in D and where it

Re: Align a variable on the stack.

2015-11-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:29:45 UTC, TheFlyingFiddle wrote: Is there a built in way to do this in dmd? Basically I want to do this: auto decode(T)(...) { while(...) { T t = T.init; //I want this aligned to 64 bytes. } } Currently I am using: align(64) struct

Re: Help with Concurrency

2015-11-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: I am having trouble with a simple use of concurrency. Running the following code I get 3 different tid's, multiple "sock in" messages printed, but no receives. I am supposed to get a "received!" for each "sock in", but I am getting

Help with Concurrency

2015-11-03 Thread bertg via Digitalmars-d-learn
I am having trouble with a simple use of concurrency. Running the following code I get 3 different tid's, multiple "sock in" messages printed, but no receives. I am supposed to get a "received!" for each "sock in", but I am getting hung up on "receiving...". Am I misusing or

Align a variable on the stack.

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
Is there a built in way to do this in dmd? Basically I want to do this: auto decode(T)(...) { while(...) { T t = T.init; //I want this aligned to 64 bytes. } } Currently I am using: align(64) struct Aligner(T) { T value; } auto decode(T)(...) { Aligner!T t = void;

Is it possible to filter variadics?

2015-11-03 Thread maik klein via Digitalmars-d-learn
Is it possible to filter variadics for example if I would call void printSumIntFloats(Ts...)(Ts ts){...} printSumIntFloats(1,1.0f,2,2.0f); I want to print the sum of all integers and the sum of all floats. //Pseudo code void printSumIntFloats(Ts...)(Ts ts){ auto sumOfInts = ts

Re: Is it possible to filter variadics?

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:41:10 UTC, maik klein wrote: Is it possible to filter variadics for example if I would call void printSumIntFloats(Ts...)(Ts ts){...} printSumIntFloats(1,1.0f,2,2.0f); I want to print the sum of all integers and the sum of all floats. //Pseudo code void

Re: foreach loop

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote: well I tried this that way, but my count stays 0, same as if I do it in an int function with a return though I clearly have some false elements in the arr. You could also use count:

Re: How to detect overflow

2015-11-03 Thread BBasile via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote: Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824 You can use core.checkedint [1] ---

Re: Help with Concurrency

2015-11-03 Thread bertg via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 01:27:57 UTC, Nicholas Wilson wrote: On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: [...] Try replacing the following loop to have a receive that times out or while(true) to while(web socked.connected) [...] That didn't solve the problem. How

How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824

Re: proper range usage

2015-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/03/2015 01:12 AM, Alex wrote: >> That problem is solved by the convention that 'end' is one beyond the >> last valid element. So, when there is only the element 42, then >> begin==42 and end==43. Only when the last element (42 in this case) is >> consumed, begin==end. >> > This part is

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 04:22:03 UTC, BBasile wrote: On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote: Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824 You can use

Re: How to detect overflow

2015-11-03 Thread Namal via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 04:22:03 UTC, BBasile wrote: On Wednesday, 4 November 2015 at 03:55:13 UTC, Namal wrote: Is there a way to detect overflow for example for: int i = 2_000_000_000; int a = i*i*i; writeln(a); -> 1073741824 You can use

Re: How to detect overflow

2015-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/03/2015 10:34 PM, Namal wrote: http://dlang.org/phobos/core_checkedint.html Is it just an error in the documentation that the return value is stated as sum for the multiplication functions? Yeah, looks like classic copy-paste errors. :) Ali

Re: Is it possible to filter variadics?

2015-11-03 Thread Jakob Ovrum via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:41:10 UTC, maik klein wrote: Is it possible to filter variadics for example if I would call void printSumIntFloats(Ts...)(Ts ts){...} printSumIntFloats(1,1.0f,2,2.0f); I want to print the sum of all integers and the sum of all floats. //Pseudo code void

Re: How to detect overflow

2015-11-03 Thread BBasile via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 07:19:09 UTC, Ali Çehreli wrote: On 11/03/2015 10:34 PM, Namal wrote: http://dlang.org/phobos/core_checkedint.html Is it just an error in the documentation that the return value is stated as sum for the multiplication functions? Yeah, looks like classic

Re: foreach loop

2015-11-03 Thread Namal via Digitalmars-d-learn
Hello guys, I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx.

Re: foreach loop

2015-11-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx. for many of them it is as simple as: foreach(index, element; array) { }

Re: foreach loop

2015-11-03 Thread wobbles via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 14:47:14 UTC, Namal wrote: Hello guys, I remember it is possible to get the index for each element in the foreach loop, but I forgot how to do it. Can you help me out please. Thx. auto arr = ["Hello", "World"]; foreach(int idx, string str; arr){