Re: extern and opaque structs

2012-05-02 Thread Jonathan M Davis
On Thursday, May 03, 2012 07:00:21 James Miller wrote: > I'm doing C bindings and I have an opaque struct and an extern'd > variable of the type of that struct. The problem is that dmd is > complaining that the struct has no definition (which is true). > Making it a pointer works (expected) but i c

extern and opaque structs

2012-05-02 Thread James Miller
I'm doing C bindings and I have an opaque struct and an extern'd variable of the type of that struct. The problem is that dmd is complaining that the struct has no definition (which is true). Making it a pointer works (expected) but i can't do that because the interface is expecting an full str

Re: Test if an enum value is in a range of a derived enum

2012-05-02 Thread bearophile
Andrej Mitrovic: This writes "yes" so cast is a blunt tool that doesn't work in this case. to!() doesn't work either (compile error, maybe I should file this) . Seems worth filing. Anyone know of any other solutions? Write your own function to perform the test, using a liner loop? Bye,

Test if an enum value is in a range of a derived enum

2012-05-02 Thread Andrej Mitrovic
import std.stdio; enum Base { One, Two, Three, Four } enum Subset : Base { Two = Base.Two, Three = Base.Three } void main() { Base base = Base.Four; if (cast(Subset)base) { writeln("yes"); } } This writes "yes" so cast is a blunt tool that doesn't

Re: Passing array as const slows down code?

2012-05-02 Thread bearophile
Joseph Rushton Wakeling: Removing the ref ups the time as described before, but only with GDC (DMD the runtime is the same). It's a real effect. There is no implicit local copy for const. I have a suspicion that you changed two things and forgot about one of them when running your tests.

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/3/12, Andrej Mitrovic wrote: > import std.stdio; > > struct Foo > { >int[] hash; > } Sorry that should have been int[int] there.

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/2/12, Jonathan M Davis wrote: > The way that AAs work in this regard is identical to how dynamic arrays > work. Yes but they're very different in other regards. For example, if you add an element to one array it doesn't automatically add an element to the other array: int[] a = new int[

Re: cannot cast

2012-05-02 Thread Namespace
Other, shorter example: [code] import std.stdio, std.traits; class A { int val; alias val this; T opCast(T : Object)() { writeln("FOO"); return to!(T)(this); } } class B : A { } T to(T : Object, U : Obj

Re: ref semantics with hashes

2012-05-02 Thread bearophile
H. S. Teoh: I was told that this was expected behaviour. It's trash behavior, bug-prone and not intuitive. It has the worst qualities of both a struct and a class :-) Should the new AA implementation change this, so that it always allocates an empty AA upon instantiation? Sounds like a po

Re: Transforming a range back to the original type?

2012-05-02 Thread bearophile
Jacob Carlborg: Is there a general function for transforming a range back to the original type? If not, would it be possible to create one? The newly redesigned containers in Scala language are often able to do this, but this has required the use of a very advanced static type system, that is

Re: Transforming a range back to the original type?

2012-05-02 Thread Jonathan M Davis
On Wednesday, May 02, 2012 23:01:21 Jacob Carlborg wrote: > Is there a general function for transforming a range back to the > original type? If not, would it be possible to create one? You mean that if you have something like auto range = getRangeFromSomewhere(); auto newRange = find(filter!func

Re: ref semantics with hashes

2012-05-02 Thread Jonathan M Davis
On Wednesday, May 02, 2012 13:32:04 H. S. Teoh wrote: > On Wed, May 02, 2012 at 09:38:35PM +0200, Andrej Mitrovic wrote: > [...] > > > So if the hash wasn't already initialized then the reference in the > > Foo struct is a reference to null, and if you duplicate that reference > > and add a key th

Re: Transforming a range back to the original type?

2012-05-02 Thread Matt Soucy
On 05/02/2012 05:01 PM, Jacob Carlborg wrote: Is there a general function for transforming a range back to the original type? If not, would it be possible to create one? I believe std.array's array function does what you want. -Matt

Transforming a range back to the original type?

2012-05-02 Thread Jacob Carlborg
Is there a general function for transforming a range back to the original type? If not, would it be possible to create one? -- /Jacob Carlborg

Re: cannot cast

2012-05-02 Thread Namespace
Can anyone tell me, why the this code [code] module RefTest.Ref; import std.stdio : writeln; import std.conv : to, toImpl; T const_cast(T : Object)(const T obj) { return cast(T) obj; } struct Ref(T : Object) { private: T _obj; public: @disable this();// { }

Re: ref semantics with hashes

2012-05-02 Thread H. S. Teoh
On Wed, May 02, 2012 at 09:38:35PM +0200, Andrej Mitrovic wrote: [...] > So if the hash wasn't already initialized then the reference in the > Foo struct is a reference to null, and if you duplicate that reference > and add a key the old reference still points to null. > > The only way to ensure a

Re: Passing array as const slows down code?

2012-05-02 Thread Joseph Rushton Wakeling
On 30/04/12 16:03, Steven Schveighoffer wrote: Try removing the ref and see if it goes back. That usage of ref should not affect anything (if anything it should be slower, since it's an extra level of indirection). Removing the ref ups the time as described before, but only with GDC (DMD the r

ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
import std.stdio; struct Foo { int[int] hash; } void main() { test1(); test2(); } void test1() { Foo foo; foo.hash[1] = 1; auto hash2 = foo.hash; hash2[2] = 2; writeln(foo.hash); // [1:1, 2:2] writeln(hash2); // [1:1, 2:2] } void test2() { Foo foo;

Access Violation in callback from sort

2012-05-02 Thread Jabb
Just got the TDPL book and it's a great read! I learn best when typing out the code myself, so I decided to make a single VisualD project and put the different exercises in separate modules. I am having problems with sort in std.algorithms - well, actually it appears to be a closure problem whe

Re: is there a difference between those two notations

2012-05-02 Thread Christian Köstlin
On 04/30/2012 11:03 PM, bearophile wrote: Christian Köstlin: reduce!((int a, int b){return a+b;})(iota(100)) reduce!("a+b")(iota(100)) Today the syntaxes I prefer are: iota(100).reduce!q{a + b}() iota(100).reduce!((a, b) => a + b)() But hopefully in some we'll have an efficient sum() funct

std.stdio File doesn't support Win UTF16 file systems?

2012-05-02 Thread Oleg Kuporosov
Hi all, Looking into the source (it uses DM's libc) did I get right that std.stdio.File can't work with UTF16 names in Windows? I've tried to find bug# but failed too. There is Issue#7648 "Can't open file (Windows UTF8)" only but UTF8 is not native for Windows filesystems anyway. Is there any

Re: "static" means too many things

2012-05-02 Thread Timon Gehr
On 05/02/2012 01:46 AM, bearophile wrote: This is the brief of some D code, it shows one consequence of the excessive overloading of the D "static" keyword: struct Foo { bool solve() { /*static*/ bool fill(int r, int c, Cell n) { // ... if (fill(r + i, c + j,