Re: How to avoid code duplication?

2015-03-31 Thread Rikki Cattermole via Digitalmars-d-learn
On 1/04/2015 7:19 p.m., Suliman wrote: Rikki, could you explain? I did not understand where it can help me Here is some example code. While I've only implemented one InputRange!string instance. You would probably have one, for just zip's and another raw text files. Keep in mind it returns onl

Re: How to avoid code duplication?

2015-03-31 Thread Suliman via Digitalmars-d-learn
Rikki, could you explain? I did not understand where it can help me

Re: How to avoid code duplication?

2015-03-31 Thread Rikki Cattermole via Digitalmars-d-learn
On 1/04/2015 6:15 p.m., Suliman wrote: The situation is next: I have got the function that get arrays of lognames and logfullname: void loginsert(string [] lognames, string [] logfullname) { if(logfullname[i].endsWith("txt")) { auto file = File(logfullname[i], "r");

Re: How to avoid code duplication?

2015-03-31 Thread Suliman via Digitalmars-d-learn
Maybe there is way to access of element of archive in the same way as to txt file? I looked, but it's seems that constructor accept only path to file. But I can't understand how to set path to unpacked element of archive.

Re: Getting associative array value by reference

2015-03-31 Thread Mark Isaacson via Digitalmars-d-learn
Not quite. You'll note that I am creating the elements in the associative array, not just iterating over them; some of them just happen to be duplicates. FWIW: That foreach happens to be over an input stream.

How to avoid code duplication?

2015-03-31 Thread Suliman via Digitalmars-d-learn
The situation is next: I have got the function that get arrays of lognames and logfullname: void loginsert(string [] lognames, string [] logfullname) { if(logfullname[i].endsWith("txt")) { auto file = File(logfullname[i], "r"); foreach (line; fi

Re: Getting associative array value by reference

2015-03-31 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 03:11:58 UTC, Mark Isaacson wrote: I'm presently trying to create the value of a key in an associative array if it does not exist, and then maintain a reference/pointer to the value. This is what I came up with, but it seems really crufty and I feel that there must

Getting associative array value by reference

2015-03-31 Thread Mark Isaacson via Digitalmars-d-learn
I'm presently trying to create the value of a key in an associative array if it does not exist, and then maintain a reference/pointer to the value. This is what I came up with, but it seems really crufty and I feel that there must be a cleaner way: Value[string] assocArray; foreach (...) {

Re: Win32 bindings

2015-03-31 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 01:09:11 UTC, Charles wrote: Are the default libraries in dmd2\windows\lib not current or something? Those only cover a small number of DLLs, and even those partially.

Re: Win32 bindings

2015-03-31 Thread Charles via Digitalmars-d-learn
http://www.dsource.org/projects/bindings/wiki/WindowsApi Thanks for this! I guess my brain was wrong thinking it'd be in http://code.dlang.org if it was still being maintained. For some functions, you'll need import libraries. You can get them from the same project as in the above link, crea

Re: Win32 bindings

2015-03-31 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 17:20:05 UTC, Charles wrote: Hi guys, What is the best (and/or official) source for win32 bindings? http://www.dsource.org/projects/bindings/wiki/WindowsApi So, perhaps, a better question is what do you use for win32 bindings? Are there any additional dependencie

Re: Win32 bindings

2015-03-31 Thread rumbu via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 17:20:05 UTC, Charles wrote: Hi guys, What is the best (and/or official) source for win32 bindings? I know there's this github project: https://github.com/AndrejMitrovic/DWinProgramming; however, it hasn't been touched in about 2 years. It's currently linked on t

Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread Laeeth Isharc via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 22:00:39 UTC, weaselcat wrote: On Tuesday, 31 March 2015 at 20:56:09 UTC, Laeeth Isharc wrote: Trying on a different beefier machine with 2.066 and 2.067 release versions installed: 1mm allocations: 2.066: 0.844s 2.067: 0.19s 10mm allocations 2.066: 1m 17.2 s 2.0

Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 20:56:09 UTC, Laeeth Isharc wrote: Trying on a different beefier machine with 2.066 and 2.067 release versions installed: 1mm allocations: 2.066: 0.844s 2.067: 0.19s 10mm allocations 2.066: 1m 17.2 s 2.067: 0m 1.15s So numbers were ballpark right before, and all

Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 20:56:09 UTC, Laeeth Isharc wrote: Trying on a different beefier machine with 2.066 and 2.067 release versions installed: 1mm allocations: 2.066: 0.844s 2.067: 0.19s 10mm allocations 2.066: 1m 17.2 s 2.067: 0m 1.15s So numbers were ballpark right before, and all

Re: using exceptions in @nogc

2015-03-31 Thread sclytrack via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 01:40:54 UTC, weaselcat wrote: was this ever solved? I did some research and saw static immutable ones suggested a few times, but they can't be chained AFAIK. Reference counted exceptions. Not solved.

Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread Laeeth Isharc via Digitalmars-d-learn
Trying on a different beefier machine with 2.066 and 2.067 release versions installed: 1mm allocations: 2.066: 0.844s 2.067: 0.19s 10mm allocations 2.066: 1m 17.2 s 2.067: 0m 1.15s So numbers were ballpark right before, and allocation on this micro-benchmark much faster.

Re: struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn
Thank you.

Re: struct variable initialized with void.

2015-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/15 11:23 AM, Adam D. Ruppe wrote: On Tuesday, 31 March 2015 at 15:12:54 UTC, ref2401 wrote: Could anyone describe me what this initialization does, please? It skips the initialization entirely, leaving the memory random instead of making it zeroes (or NaN or whatever the .init is of th

Win32 bindings

2015-03-31 Thread Charles via Digitalmars-d-learn
Hi guys, What is the best (and/or official) source for win32 bindings? I know there's this github project: https://github.com/AndrejMitrovic/DWinProgramming; however, it hasn't been touched in about 2 years. It's currently linked on the wiki (http://wiki.dlang.org/D_for_Win32). I'm also awa

Re: struct variable initialized with void.

2015-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 31, 2015 at 03:23:11PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > 3) You are initializing a private member with default construction > turned off. Here, "Struct s;" wouldn't compile because of the disabled > default constructor, but you need to set it up anyway. So you

Re: struct variable initialized with void.

2015-03-31 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 16:10:07 UTC, Adam D. Ruppe wrote: On Tuesday, 31 March 2015 at 15:59:53 UTC, John Colvin wrote: Like almost never? I can't think of any reason to ever do that. I mentioned it because of this story: https://www.schneier.com/blog/archives/2008/05/random_number_b.ht

Re: struct variable initialized with void.

2015-03-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 15:59:53 UTC, John Colvin wrote: Like almost never? I can't think of any reason to ever do that. I mentioned it because of this story: https://www.schneier.com/blog/archives/2008/05/random_number_b.html I'm sure there's better ways to do it, but since a similar t

Re: struct variable initialized with void.

2015-03-31 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 15:23:12 UTC, Adam D. Ruppe wrote: 2) you want some kind of random data, like if you are using it to seed a random number. There's often better ways of doing this, but =void might work in some cases. Like almost never? I can't think of any reason to ever do that.

Re: struct variable initialized with void.

2015-03-31 Thread Lukasz Wrzosek via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 15:12:54 UTC, ref2401 wrote: struct MyStruct { // stuff } void main(string[] args) { MyStruct s1 = void; } Could anyone describe me what this initialization does, please? When do I need to use the void initialization? By default variables are initi

Re: struct variable initialized with void.

2015-03-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 15:12:54 UTC, ref2401 wrote: Could anyone describe me what this initialization does, please? It skips the initialization entirely, leaving the memory random instead of making it zeroes (or NaN or whatever the .init is of the actual type, typically zero though).

struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn
struct MyStruct { // stuff } void main(string[] args) { MyStruct s1 = void; } Could anyone describe me what this initialization does, please? When do I need to use the void initialization?

Re: Use libusb in windows system

2015-03-31 Thread Rikki Cattermole via Digitalmars-d-learn
On 1/04/2015 2:54 a.m., Vitaly wrote: Hi, I am new in this language. Have anybody dynamic linking libusb with dmd2 on windows. I know ther is a project libusb-d but this project is for posix system. As I understand for windows I nid to add .lib file to project, but there is a problem with COFF an

Use libusb in windows system

2015-03-31 Thread Vitaly via Digitalmars-d-learn
Hi, I am new in this language. Have anybody dynamic linking libusb with dmd2 on windows. I know ther is a project libusb-d but this project is for posix system. As I understand for windows I nid to add .lib file to project, but there is a problem with COFF and OMF compatibility. Is it possible

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 31, 2015 at 11:57:49AM +, w0rp via Digitalmars-d-learn wrote: > Mutual tail call optimisation doesn't work in C++ either. > > Because it's not a language feature in C++ or D. It is not required by > the standards of either language. It's an optimisation which compilers > apply. I a

Re: lambda code

2015-03-31 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 12:49:36 UTC, Vlad Levenfeld wrote: Is there any way (or could there be any way, in the future) of getting the code from lambda expressions as a string? I've noticed that if I have an error with a lambda that looks like, say x=>x+a the error message will come u

lambda code

2015-03-31 Thread Vlad Levenfeld via Digitalmars-d-learn
Is there any way (or could there be any way, in the future) of getting the code from lambda expressions as a string? I've noticed that if I have an error with a lambda that looks like, say x=>x+a the error message will come up referring to it as (x) => x + a so some level of processing h

Re: is it std.datetime bug?

2015-03-31 Thread anonymous via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 11:51:26 UTC, drug wrote: import std.datetime; import std.stdio; void main() { long.max.SysTime.toISOExtString.writeln; } dmd 2.065 (dpaste.dzfl.pl): +29228-09-14T02:48:05.4775807 dmd v2.067-devel-c6b489b (using Digger): -29227-04-20T00:11:54.5224191 could

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 12:01:52 UTC, ketmar wrote: gdc does, as this is gcc backend optimisation. Thanks.

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 11:57:49 +, w0rp wrote: > You might want to try GDC or LDC. I am not certain if they implement > tail call optimisations, but they might do, and it seems like a good > optimisation to have. I'm sure this has been discussed before. gdc does, as this is gcc backend optimisat

Re: Mutual optimization of tail recursion does not work in D

2015-03-31 Thread w0rp via Digitalmars-d-learn
Mutual tail call optimisation doesn't work in C++ either. Because it's not a language feature in C++ or D. It is not required by the standards of either language. It's an optimisation which compilers apply. I am guessing you are using DMD, which might not offer the best optimisations for runti

Mutual optimization of tail recursion does not work in D

2015-03-31 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, This code does not work: import std.stdio; bool odd(int n); bool even(int n); bool even(int n) { if (n == 0) return true; else return odd(n - 1); } bool odd(int n) { if (n == 0) return false; else

is it std.datetime bug?

2015-03-31 Thread drug via Digitalmars-d-learn
import std.datetime; import std.stdio; void main() { long.max.SysTime.toISOExtString.writeln; } dmd 2.065 (dpaste.dzfl.pl): +29228-09-14T02:48:05.4775807 dmd v2.067-devel-c6b489b (using Digger): -29227-04-20T00:11:54.5224191 could somebody confirm it?

Re: Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread Laeeth Isharc via Digitalmars-d-learn
oops - scratch that. may have made a mistake with versions and be comparing 2.067 with some unstable dev version. On Tuesday, 31 March 2015 at 11:46:41 UTC, Laeeth Isharc wrote: I was curious to see if new DMD had changed speed on Maxime Chevalier-Boisvert's allocation benchmark here: http:/

Maxime's micro allocation benchmark much faster ?

2015-03-31 Thread Laeeth Isharc via Digitalmars-d-learn
I was curious to see if new DMD had changed speed on Maxime Chevalier-Boisvert's allocation benchmark here: http://pointersgonewild.com/2014/10/26/circumventing-the-d-garbage-collector/ I haven't had time to look at the Phobos test suite to know if this was one of those that were included, but

Re: gdc and ldc command line examples?

2015-03-31 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 04:59:35 UTC, Jeremy DeHaan wrote: Hey all, I am finally working on moving out of dmd territory and playing with gdc and ldc. I was hoping that I could get some links to some example command lines. I'm mainly interested command lines regarding linking to libraries