Variadic constructor conflict

2013-01-30 Thread andrea9940
This code compiles fine: struct Vector(T, uint SIZE) { T[SIZE] vector; this(T value) { foreach (ref v; vector) v = value; } } alias Vector!(int, 3) Vec3i; but if I add a variadic constructor: struct Vector(T, uint SI

Re: Variadic constructor conflict

2013-01-30 Thread andrea9940
Aw

Eponymous templates ambiguity

2013-08-03 Thread andrea9940
Hello D world, I have just started using templates and mixins to generate some boilerplate code and I have found a little ambiguity: This code compiles fine: private template genTypes() { string eval() { ... } const(char[]) genTypes = eval(); } mixin(genTypes!()); // Working

Re: Eponymous templates ambiguity

2013-08-03 Thread andrea9940
Thanks to both of you !

X11 XSynchronize() definition in D

2013-08-06 Thread andrea9940
Hi, I'm working with the X11 library available from https://github.com/D-Programming-Deimos/libX11 If I try to call XSynchronize(display, True) the compilation fails with "Error: function deimos.X11.Xlib.XSynchronize (_XDisplay*) is not callable using argument types (_XDisplay*, int)" I am su

Re: X11 XSynchronize() definition in D

2013-08-06 Thread andrea9940
On Tuesday, 6 August 2013 at 08:21:26 UTC, bearophile wrote: Try extern(C)? It's not a linkage error, it's a syntax one

Re: X11 XSynchronize() definition in D

2013-08-06 Thread andrea9940
@Ali Çehreli Thank you for the explanation. I'll send a pull request to fix Xlib.d

Smart way to convert a C string to a D string

2013-08-07 Thread andrea9940
Hi, I have written a function to convert a C string to a D string. I did not use to!string because it allocates a new string while what I want is a dynamic array of type char[] pointing to the C string. auto cstr2dstr(inout(char)* cstr) { import core.stdc.string: strlen; return cstr ?

Re: Smart way to convert a C string to a D string

2013-08-08 Thread andrea9940
I hadn't tought of thath, thank you for the example.

Re: Smart way to convert a C string to a D string

2013-08-17 Thread andrea9940
Excellent discovery !

Re: References

2013-09-20 Thread andrea9940
Remove the "ref" in "ref A opAdd(const ref A a) {"

References

2013-09-20 Thread andrea9940
Running this code I would expect to get "ref" three times, but ... --- import std.stdio; struct A { int[128] data; ref A opAdd(const ref A a) { A cp = this; cp.data[] += a.data[]; return cp; } } void fun(A a) { writeln("

Re: References

2013-09-20 Thread andrea9940
On Friday, 20 September 2013 at 09:44:51 UTC, Namespace wrote: This prints 'ref' if you change func(A a) to func(const A a) the match of const ref isn't prefered over A a because const need an implicit conversion. Thanks for the tip. a + b is an rvalue and will moved to func(A a). This is eve

Re: References

2013-09-20 Thread andrea9940
Output: CTor A with 42 CTor A with 23 CTor A with 65 Value call with A::65 DTor A with 65 CTor A with 1337 Value call with A::1337 DTor A with 1337 Ref call with A::42 DTor A with 23 DTor A with 42 No Postblit call. The beahvior is correct but at assembly level the compiler still cre

Struct literals bug ?

2013-09-29 Thread andrea9940
I think that I found a bug in the initialization of a struct. This program throws "a.v.y != 0" but all assert should pass... (I'm using the latest dmd version available) Code: http://pastebin.com/VHQP8DaE

Re: Struct literals bug ?

2013-09-29 Thread andrea9940
Thanks for the answer, I will use the aliases; however I just tried my code on codepad and surprising it worked without errors http://codepad.org/hp0YxIi7

Re: Struct literals bug ?

2013-09-30 Thread andrea9940
Added to bugzilla http://d.puremagic.com/issues/show_bug.cgi?id=11147

Bug with references (no casting used)

2014-02-22 Thread andrea9940
Hi everyone, I was trying to get my vector struct to use extensively references for passing parameters and I found a subtle bug which make me lose a few hour. A sample code that shows the bug is here http://pastebin.com/rvcNdjAE (fails with dmd 2.064 on linux) I think that the code is wrong