Re: Prevent copy of range in foreach

2016-08-31 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 23:38:21 UTC, Yuxuan Shui wrote: OK, this would work for cases like containers. But what if I represent buffered network input as a range (like File.byLine), and I don't want to copy the buffer all the time? Any suggestion on how to do that correctly? Then

Re: Prevent copy of range in foreach

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 18:28:20 UTC, Ali Çehreli wrote: On 08/31/2016 07:03 AM, Yuxuan Shui wrote: > I want to make a hash table that uses > std.experiment.allocator. The bucket is allocated from an > allocator, and freed in ~this(). I don't want to copy the whole > bucket in

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 19:39:36 UTC, ag0aep6g wrote: On 08/31/2016 09:23 PM, Yuxuan Shui wrote: Correct me if I'm wrong. But I believe this is only true when the source code of function is not available. Otherwise the compiler should always know if a function is actually @nogc or

Re: Template not seeming to instantiate a second time with default alias parameter

2016-08-31 Thread wobbles via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 21:35:29 UTC, ag0aep6g wrote: On 08/30/2016 11:28 PM, wobbles wrote: I'll have to try find a workaround for now :/ This seems to work and isn't too ugly: class Node(T, alias func) {/*...*/} alias Node(T) = Node!(T, (T t) => t*t); Excellent - thanks

Re: Debug prints in @nogc

2016-08-31 Thread ag0aep6g via Digitalmars-d-learn
On 08/31/2016 09:23 PM, Yuxuan Shui wrote: Correct me if I'm wrong. But I believe this is only true when the source code of function is not available. Otherwise the compiler should always know if a function is actually @nogc or not. Attributes are only inferred in certain cases where the

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 18:07:46 UTC, Cauterite wrote: On Wednesday, 31 August 2016 at 16:17:51 UTC, Yuxuan Shui wrote: No. When you use assumeUnique, you know something the compiler does know, and have to use assumeUnique to tell the compiler that (at least when you use it correctly).

Re: Prevent copy of range in foreach

2016-08-31 Thread Ali Çehreli via Digitalmars-d-learn
On 08/31/2016 07:03 AM, Yuxuan Shui wrote: > I want to make a hash table that uses > std.experiment.allocator. The bucket is allocated from an > allocator, and freed in ~this(). I don't want to copy the whole > bucket in this(this). It sounds like you are conflating the concept of a container

Re: Debug prints in @nogc

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 16:17:51 UTC, Yuxuan Shui wrote: No. When you use assumeUnique, you know something the compiler does know, and have to use assumeUnique to tell the compiler that (at least when you use it correctly). But when you use assumeNogc, it's always because you want to

Re: Multi-threading how-to

2016-08-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 31, 2016 at 05:53:27PM +, Cauterite via Digitalmars-d-learn wrote: > On Wednesday, 31 August 2016 at 17:37:25 UTC, solidstate1991 wrote: > > I decided to add a functionality that if multiple programs use the > > same instance of the library on the same computer, the messages will

Re: Multi-threading how-to

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 17:37:25 UTC, solidstate1991 wrote: I decided to add a functionality that if multiple programs use the same instance of the library on the same computer, the messages will be passed directly instead of via networking. What you're describing here is not actually

Multi-threading how-to

2016-08-31 Thread solidstate1991 via Digitalmars-d-learn
I decided to write a shared library for OSC in D despite the lack of popularity. I decided to add a functionality that if multiple programs use the same instance of the library on the same computer, the messages will be passed directly instead of via networking. Unfortunately we barely

Re: D to C++

2016-08-31 Thread Laeeth Isharc via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 12:19:33 UTC, Cauterite wrote: On Wednesday, 31 August 2016 at 11:43:12 UTC, Nick wrote: That's quite nice, but not what I'm looking for. What Calypso does, as far as I can see, is to make it possible to compile C++ and D together. I'm looking for a compiler

Re: D to C++

2016-08-31 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 12:13:38 UTC, Michael wrote: I can't imagine that's been done, and I'm not sure it will be high on anybody's list of priorities I'm afraid. A lot of work was done on automating C++ -> D, but converting D, a language intended to replace C++, to C++ itself seems a

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 15:52:18 UTC, Cauterite wrote: On Wednesday, 31 August 2016 at 15:10:11 UTC, Seb wrote: AssumeNogc is potentially dangerous, so I don't know whether it can make it directly, but only if you try you know ;-) So is assumeUnique No. When you use assumeUnique,

Re: Debug prints in @nogc

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 15:10:11 UTC, Seb wrote: AssumeNogc is potentially dangerous, so I don't know whether it can make it directly, but only if you try you know ;-) So is assumeUnique

Re: Debug prints in @nogc

2016-08-31 Thread Seb via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 19:03:06 UTC, Nordlöw wrote: On Tuesday, 30 August 2016 at 17:11:48 UTC, Johannes Pfau wrote: Nice! Here's a slightly modified version: https://dpaste.dzfl.pl/8c5ec90c5b39 This version does not need an additional delegate. It can be used like this:

Re: Prevent copy of range in foreach

2016-08-31 Thread pineapple via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 14:03:20 UTC, Yuxuan Shui wrote: I want to make a hash table that uses std.experiment.allocator. The bucket is allocated from an allocator, and freed in ~this(). I don't want to copy the whole bucket in this(this). Maybe I should use a reference counter or

Re: Prevent copy of range in foreach

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 20:30:12 UTC, Ali Çehreli wrote: On 08/30/2016 12:06 PM, Yuxuan Shui wrote: Is there a way to use a range defined with disabled post-blit in foreach? In other words, is there a way to prevent foreach from copying the range? It's not possible. You can't do much

Re: Prevent copy of range in foreach

2016-08-31 Thread mogu via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 19:06:46 UTC, Yuxuan Shui wrote: Is there a way to use a range defined with disabled post-blit in foreach? In other words, is there a way to prevent foreach from copying the range? Should I use move()? 国人?望加群:531010036 谢谢

Re: D to C++

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 11:43:12 UTC, Nick wrote: That's quite nice, but not what I'm looking for. What Calypso does, as far as I can see, is to make it possible to compile C++ and D together. I'm looking for a compiler that takes in D code and spits out either C or C++ code. Your

Re: D to C++

2016-08-31 Thread Michael via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 11:43:12 UTC, Nick wrote: On Tuesday, 30 August 2016 at 14:24:22 UTC, eugene wrote: On Tuesday, 30 August 2016 at 13:33:44 UTC, Nick wrote: Is it possible to compile from D to C++? Explanation: I do some competition programming and would like to write it in D

Re: D to C++

2016-08-31 Thread Nick via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 14:24:22 UTC, eugene wrote: On Tuesday, 30 August 2016 at 13:33:44 UTC, Nick wrote: Is it possible to compile from D to C++? Explanation: I do some competition programming and would like to write it in D instead of C++ :) maybe will help

Re: Checking all elements are unique.

2016-08-31 Thread pineapple via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: RDTSCP from dlang

2016-08-31 Thread kookman via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 08:23:57 UTC, Basile B. wrote: By the way maybe someone could post an ER in bugzilla to get RDTSCP available in iasm w/o using the byte code trick. Someone beat me to it, but see here: https://issues.dlang.org/show_bug.cgi?id=16449

Re: Checking all elements are unique.

2016-08-31 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 08:38:11 UTC, Andrea Fontana wrote: Something like this: https://dpaste.dzfl.pl/9fa55b2a7927 ? Andrea Or use findAdjacent: auto idsAreUnique = ids.array.sort.findAdjacent.empty; http://dlang.org/phobos/std_algorithm_searching.html#.findAdjacent

Re: Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
@Edwin: Thank you for the insight about indexed range. @Adrea: Thanks, this looks good. Even if I found it a little obscure at first sight, it's better than my previous solution.

Re: Checking all elements are unique.

2016-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: Checking all elements are unique.

2016-08-31 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: RDTSCP from dlang

2016-08-31 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:34:14 UTC, kookman wrote: On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote: Indeed, I want to use rdtscp to get access to the core ID it makes available (to at least know when tsc is from different cores/packages). I guess in the meantime I can use

Re: RDTSCP from dlang

2016-08-31 Thread rikki cattermole via Digitalmars-d-learn
On 31/08/2016 7:49 PM, kookman wrote: On Wednesday, 31 August 2016 at 07:36:16 UTC, rikki cattermole wrote: http://dlang.org/spec/abi.html#register_conventions That link talks about for functions defined extern(C) and extern(D), and gives specific info for win32. I'm using linux x86_64,

Re: RDTSCP from dlang

2016-08-31 Thread kookman via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:36:16 UTC, rikki cattermole wrote: http://dlang.org/spec/abi.html#register_conventions That link talks about for functions defined extern(C) and extern(D), and gives specific info for win32. I'm using linux x86_64, does that mean I can assume standard

Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C 'Cs'; My idea was to do: auto ids = Cs.map!(c => c.id);

Re: RDTSCP from dlang

2016-08-31 Thread rikki cattermole via Digitalmars-d-learn
On 31/08/2016 7:34 PM, kookman wrote: On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote: ALternatively to Rikki K's solution, you can do this to mimic the rdtscp behavior: asm { cpuid; rdtsc; // store time in locals } // bench { rdtsc; // store time in locals } // compute

Re: RDTSCP from dlang

2016-08-31 Thread kookman via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 09:04:41 UTC, Basile B. wrote: ALternatively to Rikki K's solution, you can do this to mimic the rdtscp behavior: asm { cpuid; rdtsc; // store time in locals } // bench { rdtsc; // store time in locals } // compute delta explanations here: -