Re: Is there a way to create compile-time delegates?

2010-07-19 Thread Don
Philippe Sigaud wrote: On Mon, Jul 19, 2010 at 22:01, torhu wrote: I wasn't able to make it work. Me too :( The compiler probably sees delegates as something that just can't be created at compile time, since no runtime contexts exist then. Which is reasonable. Can

Re: exern (C) linkage problem

2010-07-19 Thread bearophile
> typedef char* Cstring; > extern(C) Cstring strcmp(Cstring s1, Cstring s2); > ... You can use just a struct too: import std.string: toStringz; struct Cstring { const(char)* ptr; } extern(C) Cstring strcmp(Cstring s1, Cstring s2); Cstring toCString(T)(T[] s) { return Cstring(toStringz(

Re: Detecting a property setter?

2010-07-19 Thread Jonathan M Davis
On Monday, July 19, 2010 14:37:22 Rory McGuire wrote: > I suppose it would be seen as a bug because it possibly circumvents the > getter/setter > philosophy (If you return the internal value anyway). No, the problem is that you have _both_ a getter returning a ref and a setter. So, which does the

Re: Detecting a property setter?

2010-07-19 Thread Rory McGuire
On Mon, 19 Jul 2010 22:42:51 +0200, Philippe Sigaud wrote:On Mon, Jul 19, 2010 at 22:06, Simen kjaeraas wrote: template hasSetter(alias func) if (isCallable!(func)) {    enum hasSetter = isProperty!(func) &&        is( typeof( (){ func = ReturnType!(func).init; } ) );

Re: Detecting a property setter?

2010-07-19 Thread Rory McGuire
On Mon, 19 Jul 2010 23:25:01 +0200, Jonathan M Davis wrote: On Monday, July 19, 2010 13:42:51 Philippe Sigaud wrote: On Mon, Jul 19, 2010 at 22:06, Simen kjaeraas wrote: > template hasSetter(alias func) if (isCallable!(func)) { > >enum hasSetter = isProperty!(func) && > >is( ty

Re: Detecting a property setter?

2010-07-19 Thread Rory McGuire
On Mon, 19 Jul 2010 22:06:14 +0200, Simen kjaeraas wrote: Rory McGuire wrote: Does anyone know how to detect if there is a setter for a property? The code below prints the same thing for both the setter and the getter of "front": == import std.traits; class Fo

Re: Detecting a property setter?

2010-07-19 Thread Jonathan M Davis
On Monday, July 19, 2010 13:42:51 Philippe Sigaud wrote: > On Mon, Jul 19, 2010 at 22:06, Simen kjaeraas wrote: > > template hasSetter(alias func) if (isCallable!(func)) { > > > >enum hasSetter = isProperty!(func) && > > > >is( typeof( (){ func = ReturnType!(func).init; } ) ); > >

Re: Detecting a property setter?

2010-07-19 Thread Philippe Sigaud
On Mon, Jul 19, 2010 at 22:06, Simen kjaeraas wrote: > template hasSetter(alias func) if (isCallable!(func)) { >enum hasSetter = isProperty!(func) && >is( typeof( (){ func = ReturnType!(func).init; } ) ); > } > > In that case, for the second func, the one you call ReturnType on, how do

Re: Is there a way to create compile-time delegates?

2010-07-19 Thread Philippe Sigaud
On Mon, Jul 19, 2010 at 22:01, torhu wrote: > > > I wasn't able to make it work. Me too :( > The compiler probably sees delegates as something that just can't be > created at compile time, since no runtime contexts exist then. Which is > reasonable. > Can you initialize pointers in general,

Re: Detecting a property setter?

2010-07-19 Thread Simen kjaeraas
Rory McGuire wrote: Does anyone know how to detect if there is a setter for a property? The code below prints the same thing for both the setter and the getter of "front": == import std.traits; class Foo { uint num; @property ref uint front() {

Re: Is there a way to create compile-time delegates?

2010-07-19 Thread torhu
On 19.07.2010 21:06, Simen kjaeraas wrote: Yeah, what the subject says. I want to have a default delegate for a struct, and without a default constructor, this has to be a compile-time constant. Now, logically, there should be nothing wrong with storing the function pointer and a null context po

Detecting a property setter?

2010-07-19 Thread Rory McGuire
Hi, Does anyone know how to detect if there is a setter for a property? The code below prints the same thing for both the setter and the getter of "front": == import std.traits; class Foo { uint num; @property ref uint front() { return num;

Is there a way to create compile-time delegates?

2010-07-19 Thread Simen kjaeraas
Yeah, what the subject says. I want to have a default delegate for a struct, and without a default constructor, this has to be a compile-time constant. Now, logically, there should be nothing wrong with storing the function pointer and a null context pointer at compile-time, but it seems there is

Re: exern (C) linkage problem

2010-07-19 Thread bearophile
Lars T. Kyllingstad: > 2. For D strings in general the \0 must be added, but this is very easy > to forget. Therefore, when passing strings to C functions I always use > the std.string.toStringz() function. It takes a D string, adds a \0 if > necessary, and returns a pointer to the first chara

Re: exern (C) linkage problem

2010-07-19 Thread Lars T. Kyllingstad
On Sun, 18 Jul 2010 13:08:57 -0700, Charles Hixson wrote: > I'm trying to link a C routine to a D program, passing string > parameters, but I keep getting segmentation errors. As you can see, > these are simple test routines, so the names don't reflect current > status, but merely where I intend t