Re: Duck typing and safety.

2010-08-14 Thread Simen kjaeraas
Steven Schveighoffer schvei...@yahoo.com wrote: 1. a function may have the same name and usage, but have a completely different meaning. Human languages are funny that way. This means, your function could accept a type as a parameter and use it in a very wrong way. Most of the time,

__gshared on structs

2010-08-14 Thread Simen kjaeraas
__gshared struct foo { int n; } foo f; This f is not shared between threads, even though the __gshared indicates it should be. Why is this not an error? -- Simen

rdmd only works with files in current directory on Windows?

2010-08-14 Thread simendsjo
c:\temp\src\test.d c:\temprdmd src\test The system cannot find the path specified. c:\temprdmd src/test std.file.FileException: (...)\.rdmd\rdmd-src/test.d-(...): The system cannot find the path specified. Using rdmd 20090902, dmd 2.048 and 64 bit win7

Re: __gshared on structs

2010-08-14 Thread Trass3r
I don't think that this syntax is supported at all. You need to use __gshared with the instance instead: __gshared foo f;

typedef alternative

2010-08-14 Thread Yao G.
Hello. Is there an alternative to typedef? I need to define three structs that have exactly the same methods and properties, yet represent different stuff. Example: --- struct Foo { this( int f ) { _foo = f; } int asNumber() { return _foo; } private

Re: typedef alternative

2010-08-14 Thread Yao G.
On Sat, 14 Aug 2010 20:05:04 -0500, Jonathan M Davis jmdavisp...@gmail.com wrote: [snip] Are you looking to create a new type that while technically identical to another type is not considered the same as that type by the type system? - Jonathan M Davis Yes, This is exactly what I want. I

Re: typedef alternative

2010-08-14 Thread Jonathan M Davis
On Saturday 14 August 2010 18:15:40 Yao G. wrote: On Sat, 14 Aug 2010 20:05:04 -0500, Jonathan M Davis jmdavisp...@gmail.com wrote: [snip] Are you looking to create a new type that while technically identical to another type is not considered the same as that type by the type system?

Re: typedef alternative

2010-08-14 Thread Yao G.
On Sat, 14 Aug 2010 20:28:56 -0500, sybrandy sybra...@gmail.com wrote: I can't recall if you can do this with structs, but if you use classes, you should be able to define a Date Part class that has all of the methods and data you want. Then, you just derive three sub-classes. For example

Re: typedef alternative

2010-08-14 Thread Yao G.
On Sat, 14 Aug 2010 20:34:02 -0500, Jonathan M Davis jmdavisp...@gmail.com wrote: Well, if you search the D list for typedef, you should find some posts that suggest templated structs combined with alias which get you typedefs. It sounds like something like that will probably end up in

Re: typedef alternative

2010-08-14 Thread Yao G.
I settled this just using an enum value passed as template argument: --- enum DatePart { Year, Month, Day, } struct DatePartImpl(T : DatePart ) { // Insert implementation here... } alias DatePartImpl!(DatePart.Year) Year; alias DatePartImpl!(DatePart.Month) Month; alias

Unit tests in libraries?

2010-08-14 Thread Mike Linford
Is this a bug? Unit tests do not seem to work in libraries. I'm using dmd 1.062 for linux. mylib.d : module mylib; void blah() { } unittest { assert(false); } main.d : module main; import mylib; void main() { blah(); } The unit test does not get run when compiled as: dmd

Unit tests and verifying pre/post-conditions and invariants

2010-08-14 Thread Jonathan M Davis
Is there a standard and/or acceptable way to make sure that pre-conditions, post-conditions, or invariants _fail_ when running unit tests? That is, lets say I had a function like this void func(int x) in { assert(x 8); } body { //... } and I wanted to test to make sure that func()