Replacement of std.stream

2015-06-27 Thread DlangLearner via Digitalmars-d-learn
I will convert a Java program into D. The original Java code is based on the class RandomeAccessFile which essentially defines a set of methods for read/write Int/Long/Float/String etc. The module std.stream seems to be a good fit for this job, but in its documentation, it is marked deprecated.

Re: how to iterate on Array?

2015-06-27 Thread aki via Digitalmars-d-learn
On Saturday, 27 June 2015 at 18:32:10 UTC, Ali Çehreli wrote: On 06/27/2015 10:43 AM, aki wrote: You are rightly assuming that the loop counter is available for all container types. Unfortunately, it is the case only for arrays. Now I know. Thanks for it. aki.

how to string → uint* ?

2015-06-27 Thread xky via Digitalmars-d-learn
hello. :-) when i was using DerelictSFML2( http://code.dlang.org/packages/derelict-sfml2 ), i got this problem. CSFML doc had 'setUnicodeString': CSFML_GRAPHICS_API void sfText_setUnicodeString ( sfText * text,

Re: std.concurrent Tid vector initialization problem

2015-06-27 Thread Ali Çehreli via Digitalmars-d-learn
On 06/27/2015 06:00 PM, Charles Hixson via Digitalmars-d-learn wrote: I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The number won't be known at compile time, but that doesn't seem to change the design. All I've been able to come up w

std.concurrent Tid vector initialization problem

2015-06-27 Thread Charles Hixson via Digitalmars-d-learn
I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The number won't be known at compile time, but that doesn't seem to change the design. All I've been able to come up with is a pair of loops, one to spawn the threads, and collect their

Re: Static constructors guaranteed to run?

2015-06-27 Thread Tofu Ninja via Digitalmars-d-learn
On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why?

Re: Static constructors guaranteed to run?

2015-06-27 Thread ketmar via Digitalmars-d-learn
On Fri, 26 Jun 2015 22:00:51 +, Tofu Ninja wrote: > Are static constructors guaranteed to run if the module is imported? > Also are static constructors in templated types guaranteed to run for > every instantiation? Even if the instantiation is never actually used > outside of compile time cod

Re: how to skip sub functions in __traits(allMembers)

2015-06-27 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 16:28:40 +, BBaz wrote: > I try to build a symbol table: > > --- > module aveb; > > import std.stdio; > import std.algorithm.searching; > import std.ascii; > > void* [string] sig; > > void ana(alias mod)() > { > import std.traits; foreach(memb;__traits(allMembers,m

Re: how to iterate on Array?

2015-06-27 Thread jmh530 via Digitalmars-d-learn
On Saturday, 27 June 2015 at 18:32:10 UTC, Ali Çehreli wrote: Luckily, it is very easy to achieve it with std.range.enumerate: FTFY

is it safe to call `GC.removeRange` in dtor?

2015-06-27 Thread ketmar via Digitalmars-d-learn
is it safe to call `GC.removeRange` in dtor? i believe it should be safe, so one can perform various cleanups, but documentation says nothing about guarantees. signature.asc Description: PGP signature

Re: Static constructors guaranteed to run?

2015-06-27 Thread Timon Gehr via Digitalmars-d-learn
On 06/27/2015 11:54 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote: Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of compile time code, like in an alias or in a UDA? Definitely not. Things insid

Re: string to time conversion (when string contains time but no date)

2015-06-27 Thread Timothee Cour via Digitalmars-d-learn
thanks, missed that! On Sat, Jun 27, 2015 at 2:59 AM, via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Saturday, 27 June 2015 at 03:17:49 UTC, Timothee Cour wrote: > >> is there a way to convert a string representing a time (without date) to a >> time, eg: >> >> auto t = "

Re: how to iterate on Array?

2015-06-27 Thread Ali Çehreli via Digitalmars-d-learn
On 06/27/2015 10:43 AM, aki wrote: > void pr(Array!int a) { > foreach(i, v; a[]) { You are rightly assuming that the loop counter is available for all container types. Unfortunately, it is the case only for arrays. Luckily, it is very easy to achieve it with std.algorithm.enumerate: imp

Re: how to iterate on Array?

2015-06-27 Thread John Chapman via Digitalmars-d-learn
On Saturday, 27 June 2015 at 17:43:13 UTC, aki wrote: I want to print the contents of Array!int import std.stdio; import std.container; void pr(Array!int a) { foreach(i, v; a[]) { writeln("%4s: %s\n", i, v); } } But when I compile it by DMD 2.062 on Windows it s

how to iterate on Array?

2015-06-27 Thread aki via Digitalmars-d-learn
I want to print the contents of Array!int import std.stdio; import std.container; void pr(Array!int a) { foreach(i, v; a[]) { writeln("%4s: %s\n", i, v); } } But when I compile it by DMD 2.062 on Windows it says: testArray.d(5): Error: cannot infer argument type

how to skip sub functions in __traits(allMembers)

2015-06-27 Thread BBaz via Digitalmars-d-learn
I try to build a symbol table: --- module aveb; import std.stdio; import std.algorithm.searching; import std.ascii; void* [string] sig; void ana(alias mod)() { import std.traits; foreach(memb;__traits(allMembers,mod)) static if (canFind(["package","public"],__traits(getProtection,

Re: Autocorrelation function with ranges

2015-06-27 Thread kerdemdemir via Digitalmars-d-learn
On Saturday, 27 June 2015 at 12:17:31 UTC, Timon Gehr wrote: This computes a²·a̅ instead of a·a̅. What is the source code for residualPowerOf2? Also is there any performance issues? can I make this faster? Probably you should use http://dlang.org/phobos/std_complex.html#.sqAbs instead. Y

Re: Autocorrelation function with ranges

2015-06-27 Thread Timon Gehr via Digitalmars-d-learn
On 06/27/2015 02:17 PM, Timon Gehr wrote: You then also don't need the final map to extract the real part. (This is actually not true, your inverseFFT presumably still returns complex numbers.)

Re: aa.byKeyValue().sort!"a.key < b.key"

2015-06-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 27 June 2015 at 12:27:59 UTC, H. S. Teoh wrote: On Sat, Jun 27, 2015 at 12:22:06PM +, Nicholas Wilson via Digitalmars-d-learn wrote: How do I iterate through an AA sorted by key? I am unable to .dup the aa.byKeyValue(). Because it is a range, not an array. To turn it into an

Re: aa.byKeyValue().sort!"a.key < b.key"

2015-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 27, 2015 at 12:22:06PM +, Nicholas Wilson via Digitalmars-d-learn wrote: > How do I iterate through an AA sorted by key? > > I am unable to .dup the aa.byKeyValue(). Because it is a range, not an array. To turn it into an array, write: aa.byKeyValue().array.sort!"a.key

aa.byKeyValue().sort!"a.key < b.key"

2015-06-27 Thread Nicholas Wilson via Digitalmars-d-learn
How do I iterate through an AA sorted by key? I am unable to .dup the aa.byKeyValue(). I have tried both foreach(e; aa.byKeyValue().sort!"a.key < b.key") { //... use e. key && e.value } and foreach(k,v; aa.byKeyValue().sort!"a.key < b.key") { } i get : template std.algorithm.sorting.sort

Re: Autocorrelation function with ranges

2015-06-27 Thread Timon Gehr via Digitalmars-d-learn
On 06/27/2015 12:29 PM, kerdemdemir wrote: Hi My question is more about Maths than D lang, I am hoping, maybe somebody worked with AutoCorrelation function before. auto autoCorrelation(R)(R range) if (isRandomAccessRange!R) { auto residual = residualPowerOf2(range.length); // Fin

Re: Autocorrelation function with ranges

2015-06-27 Thread kerdemdemir via Digitalmars-d-learn
On Saturday, 27 June 2015 at 10:37:08 UTC, Rikki Cattermole wrote: No idea about the maths behind it are but: Thanks a lot for your answer anyway. I am hoping even not related with D directly, this discussions may atract people from other languages to D while looking for Domain information.

Re: Autocorrelation function with ranges

2015-06-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 27/06/2015 10:29 p.m., kerdemdemir wrote: Hi My question is more about Maths than D lang, I am hoping, maybe somebody worked with AutoCorrelation function before. auto autoCorrelation(R)(R range) if (isRandomAccessRange!R) { auto residual = residualPowerOf2(range.length); // F

Autocorrelation function with ranges

2015-06-27 Thread kerdemdemir via Digitalmars-d-learn
Hi My question is more about Maths than D lang, I am hoping, maybe somebody worked with AutoCorrelation function before. auto autoCorrelation(R)(R range) if (isRandomAccessRange!R) { auto residual = residualPowerOf2(range.length); // Find how many zeros to add auto fftResult

Re: string to time conversion (when string contains time but no date)

2015-06-27 Thread via Digitalmars-d-learn
On Saturday, 27 June 2015 at 03:17:49 UTC, Timothee Cour wrote: is there a way to convert a string representing a time (without date) to a time, eg: auto t = "19:03:40.143656"; auto a=SysTime.fromTimeString(t); // doesn't exist My current workaround is to append a dummy date before and then

Re: Static constructors guaranteed to run?

2015-06-27 Thread via Digitalmars-d-learn
On Friday, 26 June 2015 at 22:00:54 UTC, Tofu Ninja wrote: Are static constructors guaranteed to run if the module is imported? AFAIK, yes. Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of c