Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-09 Thread Nick Treleaven
On Tue, 08 Mar 2011 15:25:27 -0500, Steven Schveighoffer wrote: Hey, wouldn't it be cool if I could add a custom allocator to all classes!?... class Collection(T, alloc = DefaultAllocator!T) { Collection!(T) add(T t) { ...; return this; } // 20 other now subtly incorrect functions

Re: Mocking framework

2011-03-09 Thread simendsjo
I gave this some thought, and I'm probably just a bit braindamaged by C#. Consider you wish to unittest a class that fetches data from a database and sends an email. The common scenario here is to use IoC and mock the objects so you can check that FetchData was called and SendEmail is called

Iterating over 0..T.max

2011-03-09 Thread Magnus Lie Hetland
In a (template) data structure I'm working on, I had the following thinko: auto a = new T[n]; foreach (T i, ref e; a) { e = i; } Then I instantiated it with T=bool, and n=256. Infinite loop, of course -- the problem being that i wraps around to 0 after the last iteration.

struct opEquals

2011-03-09 Thread SiegeLord
1) Why does this code not work (dmd 2.051) and how do I fix it: struct S { static S New() { S s; return s; } const bool opEquals(ref const(S) s) { return true; } } void main() { S s;

Re: struct opEquals

2011-03-09 Thread Steven Schveighoffer
On Wed, 09 Mar 2011 11:40:25 -0500, SiegeLord n...@none.com wrote: 1) Why does this code not work (dmd 2.051) and how do I fix it: struct S { static S New() { S s; return s; } const bool opEquals(ref const(S) s) {

Re: struct opEquals

2011-03-09 Thread SiegeLord
Steven Schveighoffer Wrote: It's a mis-designed feature of structs. There is a bug report on it: http://d.puremagic.com/issues/show_bug.cgi?id=3659 It worked fine in D1. Or did you mean that the mis-designed feature is the const system? Anyway, thanks for the link to the bug report. I'll

Re: struct opEquals

2011-03-09 Thread Steven Schveighoffer
On Wed, 09 Mar 2011 12:15:26 -0500, SiegeLord n...@none.com wrote: Steven Schveighoffer Wrote: It's a mis-designed feature of structs. There is a bug report on it: http://d.puremagic.com/issues/show_bug.cgi?id=3659 It worked fine in D1. Or did you mean that the mis-designed feature is

Re: Iterating over 0..T.max

2011-03-09 Thread Kai Meyer
On 03/09/2011 09:09 AM, Magnus Lie Hetland wrote: In a (template) data structure I'm working on, I had the following thinko: auto a = new T[n]; foreach (T i, ref e; a) { e = i; } Then I instantiated it with T=bool, and n=256. Infinite loop, of course -- the problem being that i wraps around to

Re: full ident name without mangle/demange?

2011-03-09 Thread Tomek Sowiński
Nick Sabalausky napisał: Is there a way to get the fully-qualified name of an identifier without doing demange( mangledName!(foo) )? Heh, looks like there isn't. It may be worth filing an enhancement request for __traits(fullyQualifiedName, foo). BTW, what do you need it for? -- Tomek

Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread Tom
What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] TIA, Tom;

I seem to be able to crash writefln

2011-03-09 Thread Joel Christensen
This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit ) f.close; string foo = bar;

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread bearophile
Tom: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] Two versions, I have done no benchmarks so far: import std.c.stdio: printf; union Four { ubyte[4] a; uint u; } void showFour(Four f) {

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread Kai Meyer
On 03/09/2011 03:41 PM, Tom wrote: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] TIA, Tom; I don't know of anything more efficient than: ubyte[4] bytes = [1,2,3,4]; bytes = bytes[$-1] ~

std.path.shell throws exception with garbage string

2011-03-09 Thread Andrej Mitrovic
import std.process; void main() { char[] chBuffer = new char[](256); chBuffer[] = '\0'; chBuffer[0..3] = dir.dup; auto result = shell(chBuffer.idup); } It does two things: 1. It prints out the result of the shell invocation to stdout. This shouldn't happen. 2. It throws

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread Jonathan M Davis
On Wednesday, March 09, 2011 15:35:29 Kai Meyer wrote: On 03/09/2011 03:41 PM, Tom wrote: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] TIA, Tom; I don't know of anything more efficient than:

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread Kai Meyer
On 03/09/2011 04:25 PM, bearophile wrote: Tom: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] Two versions, I have done no benchmarks so far: import std.c.stdio: printf; union Four { ubyte[4] a;

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread spir
On 03/10/2011 12:55 AM, Jonathan M Davis wrote: I don't know of anything more efficient than: ubyte[4] bytes = [1,2,3,4]; bytes = bytes[$-1] ~ bytes[0..$-1]; // Rotate left I'm stunned that this works. I'd even consider reporting it as a bug. You're concatenating a ubyte[] ont a

Re: I seem to be able to crash writefln

2011-03-09 Thread spir
On 03/10/2011 12:19 AM, Joel Christensen wrote: This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit ) f.close; string foo = bar;

Re: std.path.shell throws exception with garbage string

2011-03-09 Thread Andrej Mitrovic
Found myself a solution. And probably the cause of the issue. shell() doesn't expect a null-terminated string, but just a string with the shell command without any newlines or nulls. So I can do this (importing std.algorithm for until): auto command = to!string(chBuffer[].until('\n'));

Re: std.path.shell throws exception with garbage string

2011-03-09 Thread Jonathan M Davis
On Wednesday, March 09, 2011 15:55:07 Andrej Mitrovic wrote: import std.process; void main() { char[] chBuffer = new char[](256); chBuffer[] = '\0'; chBuffer[0..3] = dir.dup; auto result = shell(chBuffer.idup); } It does two things: 1. It prints out the result of

Commenting out a print slows my code?

2011-03-09 Thread Charles McAnany
Hi, all. I'm in college, taking a freshman-level CS class. (I'm actually a senior chemist with free time.) Anyhoo, the warm-up assignment was Hardy Taxi problem, phrased like this: [Exposition removed.] 1729 is the smallest number such that for (a!=b!=c!=d)0, there exists a combination of a, b, c,

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread U2 fan
== Quote from bearophile (bearophileh...@lycos.com)'s article Tom: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] Two versions, I have done no benchmarks so far: import std.c.stdio: printf; union Four

Re: Commenting out a print slows my code?

2011-03-09 Thread Jesse Phillips
Charles McAnany Wrote: (There's also a StopWatch timing things, and isTaxiNumber returns a struct, not a bool. See attached code.) This code runs in about 0.09 seconds. If I comment out the writefln, it takes 0.11 seconds. (These are collected from about 20 runs of each. Times are very

Re: I seem to be able to crash writefln

2011-03-09 Thread Joel Christensen
On 10-Mar-11 1:04 PM, spir wrote: On 03/10/2011 12:19 AM, Joel Christensen wrote: This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit

Re: I seem to be able to crash writefln

2011-03-09 Thread Andrew Wiley
On Wed, Mar 9, 2011 at 5:19 PM, Joel Christensen joel...@gmail.com wrote: This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() {        auto f = File( z.txt, w );      

Re: Best way in D2 to rotate a ubyte[4] array

2011-03-09 Thread Andrew Wiley
On Wed, Mar 9, 2011 at 7:25 PM, U2 fan i...@u2fan.com wrote: == Quote from bearophile (bearophileh...@lycos.com)'s article Tom: What is the most efficient way of implement a rotation of ubyte[4] array? By rotation I mean: rotateRight([1, 2, 3, 4]) - [4, 1, 2, 3] Two versions, I have done

Re: I seem to be able to crash writefln

2011-03-09 Thread Andrew Wiley
On Thu, Mar 10, 2011 at 1:31 AM, Jonathan M Davis jmdavisp...@gmx.com wrote: On Wednesday 09 March 2011 23:15:13 Andrew Wiley wrote: On Wed, Mar 9, 2011 at 5:19 PM, Joel Christensen joel...@gmail.com wrote: This is on Windows 7. Using a def file to stop the terminal window coming up.