Re: How to avoid code duplication?

2015-04-01 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-04-01 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

Re: How to avoid code duplication?

2015-04-01 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-04-01 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: Maxime's micro allocation benchmark much faster ?

2015-04-01 Thread FG via Digitalmars-d-learn
On 2015-03-31 at 22:56, Laeeth Isharc wrote: 1mm allocations 2.066: 0.844s 2.067: 0.19s That is great news, thanks! OT: it's a nasty financier's habit to write 1M and 1MM instead of 1k and 1M. :P

Re: Maxime's micro allocation benchmark much faster ?

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 10:09:12 UTC, FG wrote: On 2015-03-31 at 22:56, Laeeth Isharc wrote: 1mm allocations 2.066: 0.844s 2.067: 0.19s That is great news, thanks! OT: it's a nasty financier's habit to write 1M and 1MM instead of 1k and 1M. :P Yeah, what's with that? I've never

Re: struct variable initialized with void.

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 16:24:02 UTC, John Colvin wrote: 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:

Speed of horizontal flip

2015-04-01 Thread tchaloupka via Digitalmars-d-learn
Hi, I have a bunch of square r16 and png images which I need to flip horizontally. My flip method looks like this: void hFlip(T)(T[] data, int w) { import std.datetime : StopWatch; StopWatch sw; sw.start(); foreach(int i; 0..w) { auto row =

Re: Speed of horizontal flip

2015-04-01 Thread bearophile via Digitalmars-d-learn
tchaloupka: Am I doing something utterly wrong? If you have to perform performance benchmarks then use ldc or gdc. Also disable bound tests with your compilation switches. Sometimes reverse() is not efficient, I think, it should be improved. Try to replace it with a little function written

C++ to D

2015-04-01 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Please help rewrite this code to D: #include iostream // Peano Arithmetic struct zero; template typename T struct succ { }; template typename T struct increment { using result = succT; }; template typename T struct decrement; template typename T struct decrementsuccT {

Re: Maxime's micro allocation benchmark much faster ?

2015-04-01 Thread Laeeth Isharc via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 10:35:05 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 10:09:12 UTC, FG wrote: On 2015-03-31 at 22:56, Laeeth Isharc wrote: 1mm allocations 2.066: 0.844s 2.067: 0.19s That is great news, thanks! OT: it's a nasty financier's habit to write 1M and 1MM

CURL to get/set cookies

2015-04-01 Thread Benjamin via Digitalmars-d-learn
Hello! I’m having issues with setting a cookie via CURL(std.net.curl). I’ve tried several time over the last week but can’t figure it out. I feel like I've tried every suggestion I found searching the web. Basically - I receive the value set-cookie from a GET request (got this), but have

Re: CURL to get/set cookies

2015-04-01 Thread Adam D. Ruppe via Digitalmars-d-learn
There's two ways, you can let curl handle it by setting a cookie jar file: http://dlang.org/phobos/std_net_curl.html#setCookieJar Make the HTTP object and set the jar on it before doing any requests. Then it will be done automatically on that object, saving to the file. If you are manually

Re: Maxime's micro allocation benchmark much faster ?

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 14:22:57 UTC, Laeeth Isharc wrote: On Wednesday, 1 April 2015 at 10:35:05 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 10:09:12 UTC, FG wrote: On 2015-03-31 at 22:56, Laeeth Isharc wrote: 1mm allocations 2.066: 0.844s 2.067: 0.19s That is great news,

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 13:59:10 UTC, Dennis Ritchie wrote: snip You can do this: import std.typetuple; //helper for staticReduce template Alias(alias a) { alias Alias = a; } // staticReduce should really be in std.typetuple, or // the soon to arrive std.meta package. template

Re: Speed of horizontal flip

2015-04-01 Thread tchaloupka via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 14:00:52 UTC, bearophile wrote: tchaloupka: Am I doing something utterly wrong? If you have to perform performance benchmarks then use ldc or gdc. I tried it on my slower linux box (i5-2500K vs i7-2600K) without change with these results: C# (mono with

Re: Speed of horizontal flip

2015-04-01 Thread tchaloupka via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 16:08:14 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 13:52:06 UTC, tchaloupka wrote: snip I'm pretty sure that the flipping happens in GDI+ as well. You might be writing C#, but the code your calling that's doing all the work is C and/or C++, quite

Re: Speed of horizontal flip

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 13:52:06 UTC, tchaloupka wrote: snip I'm pretty sure that the flipping happens in GDI+ as well. You might be writing C#, but the code your calling that's doing all the work is C and/or C++, quite possibly carefully optimised over many years by microsoft. Are

Re: lambda code

2015-04-01 Thread ketmar via Digitalmars-d-learn
On Tue, 31 Mar 2015 13:25:46 +, John Colvin wrote: Short answer: no. .codeof for functions is something I've wanted for ages, but no movement so far. 'cause `.codeof` is a can of worms. it is just a bad replace for AST macros, and having it means that internal string representation should

Re: Speed of horizontal flip

2015-04-01 Thread thedeemon via Digitalmars-d-learn
std.algorithm.reverse uses ranges, and shamefully DMD is really bad at optimizing away range-induced costs.

Re: lambda code

2015-04-01 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 13:25:47 UTC, John Colvin wrote: 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

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
Yess.but there are LOTS of nodes/BTree, and each node would need to check whether the btFile was already initialized, et (ugh!) cetera. So while possible, that's an even worse answer than depending on people closing the BTree properly. I *am* going to separate the close routine from the

Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
The class Node is contained within the struct BTree. The field btFile is contained within the struct BTree. The statement is within a function within the Node class. I've tried many variations, here are a few: btFile.write(self.nodeId, cast(void*)(self)); results in: need 'this' for 'btFile'

Re: C++ to D

2015-04-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all that C++ style mess. Yes, CTFE in D really cool. Thanks. I need to implement arithmetic (addition / subtraction) only use the type

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 17:03:34 UTC, Dennis Ritchie wrote: On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all that C++ style mess. Yes, CTFE in D really cool. Thanks. I need

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 17:51:40 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 17:03:34 UTC, Dennis Ritchie wrote: On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread anonymous via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 18:26:49 UTC, Charles Hixson wrote: Perhaps BTree needs to be a class? yes

Re: Maxime's micro allocation benchmark much faster ?

2015-04-01 Thread FG via Digitalmars-d-learn
On 2015-04-01 at 16:52, John Colvin wrote: On Wednesday, 1 April 2015 at 14:22:57 UTC, Laeeth Isharc wrote: On Wednesday, 1 April 2015 at 10:35:05 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 10:09:12 UTC, FG wrote: On 2015-03-31 at 22:56, Laeeth Isharc wrote: 1mm allocations 2.066:

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Charles Hixson via Digitalmars-d-learn
On 04/01/2015 11:39 AM, anonymous via Digitalmars-d-learn wrote: On Wednesday, 1 April 2015 at 18:26:49 UTC, Charles Hixson wrote: Perhaps BTree needs to be a class? yes Thanks. Sigh. I was hoping to preserve the determinate closing that one gets with a struct.

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 18:26:49 UTC, Charles Hixson wrote: Perhaps BTree needs to be a class? I made it a struct because I want it to definitely close properly when it goes out of scope. Maybe `scoped` can help: http://dlang.org/phobos/std_typecons.html#.scoped

some memory allocation/GC benchmarks here - fwiw

2015-04-01 Thread Laeeth Isharc via Digitalmars-d-learn
(not translated into D yet) http://blog.mgm-tp.com/2013/12/benchmarking-g1-and-other-java-7-garbage-collectors/ http://www.mm-net.org.uk/resources/benchmarks.html http://www.ccs.neu.edu/home/will/GC/sourcecode.html http://yoda.arachsys.com/csharp/benchmark.html it's possible we already have

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 04/01/2015 11:25 AM, Charles Hixson via Digitalmars-d-learn wrote: The class Node is contained within the struct BTree. The field btFile is contained within the struct BTree. The statement is within a function within the Node class. I've tried many variations, here are a few: