Re: Zipped sorting

2012-09-24 Thread Dmitry Olshansky
On 25-Sep-12 06:18, bearophile wrote: This line of code sorts two arrays in "lock step", according to the items of the first array: zip(first, second).sort!q{a[0] < b[0]}(); This code is handy, nice looking, short and sufficiently easy to recognize once you have seen it before. Analyzing asm

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: > [SNIP] I don't think this does what you think it does. The 'is(R r)' declares r to be an alias for R. So 'r' is a type in that code snippet. Darn :( Also, is(typeof(takeExactly(R,

Re: How do I use std.zlib to write a struct of data to a binary file with compression?

2012-09-24 Thread Dmitry Olshansky
On 25-Sep-12 00:10, TJB wrote: Hello, I am trying to save some data to compressed binary files. I have my data in a struct, which I can write to a binary file just fine: align(1) struct TradesBin { Just a note: recently compiler changed so this align(1) have no effect on the fields alignmen

Re: Passing associative array to another thread

2012-09-24 Thread Jacob Carlborg
On 2012-09-25 00:47, Sean Kelly wrote: If you're passing via std.concurrency then you'll currently have to cast to shared. I'd been considering allowing Unique!T to be sent as well, but haven't done so yet. Hey, if it's immutable why use std.concurrency at all? Just import the module and u

Re: Zipped sorting

2012-09-24 Thread cal
On Tuesday, 25 September 2012 at 02:17:53 UTC, bearophile wrote: This line of code sorts two arrays in "lock step", according to the items of the first array: zip(first, second).sort!q{a[0] < b[0]}(); Tangential to your point, but I hadn't seen the q{} syntax used before. Are there reasons t

Zipped sorting

2012-09-24 Thread bearophile
This line of code sorts two arrays in "lock step", according to the items of the first array: zip(first, second).sort!q{a[0] < b[0]}(); This code is handy, nice looking, short and sufficiently easy to recognize once you have seen it before. It's one case where D code is better than a Python

Re: How do I use std.zlib to write a struct of data to a binary file with compression?

2012-09-24 Thread TJB
Since you're already set up with the Stream interface, try creating a MemoryStream instead of a BufferedFile. Write to the stream just as you are now, then use the .data() property (on MemoryStream's superclass, TArrayStream) to get an array of raw bytes. You can feed this array into the comp

Re: Passing associative array to another thread

2012-09-24 Thread Sean Kelly
On Sep 22, 2012, at 2:24 AM, Martin Drasar wrote: > On 21.9.2012 19:01, Jacob Carlborg wrote: >> Perhaps declaring the associative array as "shared". An alternative >> would be to serialize the aa, pass it to another thread, and deserialize >> it. That would though create a copy. > > Hi Jacob, >

Re: FormattedRead hex string

2012-09-24 Thread Jason Spencer
On Monday, 24 September 2012 at 16:32:45 UTC, monarch_dodra wrote: On Monday, 24 September 2012 at 15:05:54 UTC, Jason Spencer wrote: I imagine there's a slick way to do this, but I'm not seeing it. I have a string of hex digits which I'd like to convert to an array of 8 ubytes: 0123456789a

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread Timon Gehr
On 09/24/2012 09:41 AM, monarch_dodra wrote: ... Regarding the ".init" issue, I hadn't thought of that, but it can be worked around pretty easily with an is(R r): template Hello(R) if ( is(R r) && is(typeof(takeExactly(r, 1))) && is(R == typeof(takeExactly(r

Re: How do I use std.zlib to write a struct of data to a binary file with compression?

2012-09-24 Thread Justin Whear
On Mon, 24 Sep 2012 22:10:04 +0200, TJB wrote: > Hello, > > I am trying to save some data to compressed binary files. I have my > data in a struct, which I can write to a binary file just fine: > > align(1) struct TradesBin { >int ttim; int prc; >int siz; short g127; short corr; char[2]

How do I use std.zlib to write a struct of data to a binary file with compression?

2012-09-24 Thread TJB
Hello, I am trying to save some data to compressed binary files. I have my data in a struct, which I can write to a binary file just fine: align(1) struct TradesBin { int ttim; int prc; int siz; short g127; short corr; char[2] cond; char ex; } auto fout = new BufferedFile(outfi

Re: Stupid scope destruction question

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 17:49:22 UTC, Ali Çehreli wrote: On 09/24/2012 12:49 AM, monarch_dodra wrote: > On Monday, 24 September 2012 at 07:25:28 UTC, Denis Shelomovskij wrote: >> 20.09.2012 15:35, monarch_dodra пишет: >>> >>> AFAIK, if the rules are the same in C++ (which they probably ar

Re: Stupid scope destruction question

2012-09-24 Thread Ali Çehreli
On 09/24/2012 12:49 AM, monarch_dodra wrote: > On Monday, 24 September 2012 at 07:25:28 UTC, Denis Shelomovskij wrote: >> 20.09.2012 15:35, monarch_dodra пишет: >>> >>> AFAIK, if the rules are the same in C++ (which they probably are), then: >>> "Any object constructed during argument passing wi

Re: memory de-allocation?

2012-09-24 Thread freeman
On Monday, 24 September 2012 at 00:16:33 UTC, freeman wrote: Given: void main () { system("rdmd prog_one.d"); //... output from prog_one system("rdmd prog_two.d"); //... output again from prog_one and new output from prog_two. } Any suggestions for getting rid of the ghost of prog_one?

Re: FormattedRead hex string

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 15:05:54 UTC, Jason Spencer wrote: I imagine there's a slick way to do this, but I'm not seeing it. I have a string of hex digits which I'd like to convert to an array of 8 ubytes: 0123456789abcdef --> [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF] I'm loo

FormattedRead hex string

2012-09-24 Thread Jason Spencer
I imagine there's a slick way to do this, but I'm not seeing it. I have a string of hex digits which I'd like to convert to an array of 8 ubytes: 0123456789abcdef --> [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF] I'm looking at std.format.formattedRead, but the documentation is...lighti

Re: static init cycle detection problem

2012-09-24 Thread Steven Schveighoffer
On Wed, 19 Sep 2012 16:25:46 -0400, Øivind wrote: I am struggeling to get around the cycle detection kicking in when I have static init in modules that depend on eachother. I have seen some threads on 'fixes' for this, e.g. adding a @standalone property to the module or similar. Has there

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 11:39:08 UTC, monarch_dodra wrote: Oh. I think I just got what your "reassign" was meant to do. I think I see it now. I guess it does work nice actually. I'd say that unfortunately, your *new* reassign is making the assumption that it is possible to grab a refe

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 10:53:47 UTC, comco wrote: Yes, I don't claim that - the last thing is just nasty. It's just playing with constructs seeing how far can we go. By the way, now I use the reassign function all over the place! I'm also very glad this discussion ends with a (remote

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 07:00:37 UTC, monarch_dodra wrote: On Sunday, 23 September 2012 at 21:44:20 UTC, comco wrote: [SNIP] Now we can implement our rotate in terms of reassign: void rotate(node* u) { auto v = u.right; reassign(u.right, v.left, u); } This works and is g

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread Jonathan M Davis
On Monday, September 24, 2012 10:02:54 monarch_dodra wrote: > Well, it does work... > > struct S > { > @disable this(); > } > > void foo(T)(T i) > if ( is(T t)) > {} > > void main() > { > //S s; //Fail > S s = void; > foo(s); //Works > } > > I think it makes sense that

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 07:51:23 UTC, Jonathan M Davis wrote: On Monday, September 24, 2012 09:41:26 monarch_dodra wrote: Regarding the ".init" issue, I hadn't thought of that, but it can be worked around pretty easily with an is(R r): template Hello(R) if ( is(R r) &&

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread Jonathan M Davis
On Monday, September 24, 2012 09:41:26 monarch_dodra wrote: > Regarding the ".init" issue, I hadn't thought of that, but it can > be worked around pretty easily with an is(R r): > > > template Hello(R) > if ( is(R r) && >is(typeof(takeExactly(r, 1))) && >is(R

Re: Stupid scope destruction question

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 07:25:28 UTC, Denis Shelomovskij wrote: 20.09.2012 15:35, monarch_dodra пишет: AFAIK, if the rules are the same in C++ (which they probably are), then: "Any object constructed during argument passing will remain valid for the duration of the call. It will go ou

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread monarch_dodra
On Monday, 24 September 2012 at 07:07:16 UTC, Jonathan M Davis wrote: On Monday, September 24, 2012 08:21:46 monarch_dodra wrote: template Hello(R) if ( is(typeof(takeExactly(R.init, 1))) && is(R == typeof(takeExactly(R.init, 1))) ) { alias R Hello; } What is wrong wi

Re: Stupid scope destruction question

2012-09-24 Thread Denis Shelomovskij
20.09.2012 15:35, monarch_dodra пишет: On Thursday, 20 September 2012 at 09:31:45 UTC, Denis Shelomovskij wrote: 20.09.2012 13:27, Denis Shelomovskij пишет: Is there any guaranties that `ScopeTemp` will not be destroyed before `f` call because it isn't used? --- ... f(ScopeTemp(...).value);

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread Jonathan M Davis
On Monday, September 24, 2012 08:21:46 monarch_dodra wrote: > template Hello(R) > if ( is(typeof(takeExactly(R.init, 1))) && > is(R == typeof(takeExactly(R.init, 1))) > ) > { > alias R Hello; > } > What is wrong with my proposed solution? It may work, but again, it's rely

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread monarch_dodra
On Sunday, 23 September 2012 at 21:44:20 UTC, comco wrote: [SNIP] Now we can implement our rotate in terms of reassign: void rotate(node* u) { auto v = u.right; reassign(u.right, v.left, u); } This works and is general enough, but notice the duplication of u.right. I don't l