Re: block file reads and lazy utf-8 decoding

2015-12-09 Thread Jon D via Digitalmars-d-learn
On Thursday, 10 December 2015 at 00:36:27 UTC, Jon D wrote: Question I have is if there is a better way to do this. For example, a different way to construct the lazy 'decodeUTF8Range' rather than writing it out in this fashion. A further thought - The decodeUTF8Range function is basically co

block file reads and lazy utf-8 decoding

2015-12-09 Thread Jon D via Digitalmars-d-learn
I want to combine block reads with lazy conversion of utf-8 characters to dchars. Solution I came with is in the program below. This works fine. Has good performance, etc. Question I have is if there is a better way to do this. For example, a different way to construct the lazy 'decodeUTF8Rang

Re: Reason for 'static struct'

2015-12-09 Thread Jon D via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 21:23:03 UTC, Daniel Kozák wrote: V Wed, 09 Dec 2015 21:10:43 + Jon D via Digitalmars-d-learn napsáno: There is a fair bit of range related code in the standard library structured like: auto MyRange(Range)(Range r) if (isInputRange!Range)

Re: Reason for 'static struct'

2015-12-09 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 09 Dec 2015 21:10:43 + Jon D via Digitalmars-d-learn napsáno: > There is a fair bit of range related code in the standard library > structured like: > > auto MyRange(Range)(Range r) > if (isInputRange!Range) > { > static struct Result > { >

Re: AA struct hashing bug?

2015-12-09 Thread ketmar via Digitalmars-d-learn
heh. it crashed due to "in" presence. if you'll remove "in", it will work.

Reason for 'static struct'

2015-12-09 Thread Jon D via Digitalmars-d-learn
There is a fair bit of range related code in the standard library structured like: auto MyRange(Range)(Range r) if (isInputRange!Range) { static struct Result { private Range source; // define empty, front, popFront, etc }

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:23:00 UTC, Tim K. wrote: On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: Is there a convenience function that allows me to remove an/all object(s) with a certain value from an array or do I need to write one myself? Here are some elements of str

Re: benchmark on binary trees

2015-12-09 Thread visitor via Digitalmars-d-learn
version with apr (like in c version) http://dpaste.dzfl.pl/68c0157225e7 compiled with ldc it's indeed a bit faster on average : real0m1.999s user0m9.810s sys 0m0.148 btw Rust version is even faster than my little bit outdated gcc (4.9) latest try with allocators : http://dpaste.dzf

Re: Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 11:46:45 UTC, Kagamin wrote: Allocators usually use global state. Such code is usually treated as impure. What about containers that store their own local allocator? Will DMD infer all members of such containers to be pure if they only access locally allocated

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: 3) opEquals can be 'const' because the method doesn't mutate the state of the object 4) your cast wasn't safe http://dlang.org/phobos/std_algorithm_mutation.html#.remove Maybe something like this works better: ... override bool

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:23:00 UTC, Tim K. wrote: On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: 1) remove works with an index I guess I did read it wrong. Sorry. Is there a convenience function that allows me to remove an/all object(s) with a certain value from an arra

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread Tim K. via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: 1) remove works with an index I guess I did read it wrong. Sorry. Is there a convenience function that allows me to remove an/all object(s) with a certain value from an array or do I need to write one myself? 2) remove does not rem

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread BBaz via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:05:31 UTC, Tim K. wrote: Hi! I'm trying to remove an item from an array of objects. But I get error messages when compiling (see below) which I do not understand. I figured I had to override opEquals for it to work, but no. How do I get this to work? You

std.algorithm.remove from array of custom classes?

2015-12-09 Thread Tim K. via Digitalmars-d-learn
Hi! I'm trying to remove an item from an array of objects. But I get error messages when compiling (see below) which I do not understand. I figured I had to override opEquals for it to work, but no. How do I get this to work? Regards class A { this(string si, uint ui) { s

Re: Container Purity

2015-12-09 Thread Kagamin via Digitalmars-d-learn
Allocators usually use global state. Such code is usually treated as impure.

Re: Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 10:47:18 UTC, Nordlöw wrote: that uses std.experimental.container Correction: I mean std.experimental.allocator

Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
Is it currently possible for a container such as https://github.com/economicmodeling/containers/blob/master/src/containers/dynamicarray.d that uses std.experimental.container to be completely pure? If not can be made to? I wonder because only length(), empty(), front() and back() are tagged a

Re: Real Time-ing

2015-12-09 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 16:40:04 UTC, Taylor Hillegeist wrote: However i seem to get jitter of around 1 ms. Is there anything else i can do to improve? Do you want to get precision better than period of thread switches?

Re: Real Time-ing

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 10:00:46 UTC, Andrea Fontana wrote: On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist wrote: So, I mostly do programming that is of run to completion verity. But I have a dream of calling functions periodically. So my question is: What is the best

Re: Real Time-ing

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist wrote: So, I mostly do programming that is of run to completion verity. But I have a dream of calling functions periodically. So my question is: What is the best (most time accurate) way to call a function every n time units? Wha