Re: No $ for op overloads?

2009-09-04 Thread Jarrett Billingsley
On Sat, Sep 5, 2009 at 1:31 AM, Nick Sabalausky wrote:
> I made a simple struct that overloads opIndex and opSlice, and also exposed
> a "length" property. But when I try to use $ on it, I got:
>
> Error: undefined identifier __dollar
>
> I tried making a property "__dollar" that just returned "length", but that
> didn't change anything.
>
> What's going on? Any ideas?

Nope, it's never been possible. :(

You can do silly things like defining a global __dollar, but it's
useless since it can't take params.


No $ for op overloads?

2009-09-04 Thread Nick Sabalausky
I made a simple struct that overloads opIndex and opSlice, and also exposed 
a "length" property. But when I try to use $ on it, I got:

Error: undefined identifier __dollar

I tried making a property "__dollar" that just returned "length", but that 
didn't change anything.

What's going on? Any ideas? 




Re: delegate !is null

2009-09-04 Thread Steven Schveighoffer

On Fri, 04 Sep 2009 14:33:12 -0400, Saaa  wrote:


class C
{
  private int i;
  int method()
  {
return i;
  }
}

class D
{
  private int delegate(void) _deleg;
  this(int delegate(void) d)
  {
_deleg = d;
  }
  void write()
  {
if(_deleg !is null)
}
  writef(_deleg());
}
  }
}
C c = null;
D d = new d;
d.function(c.method());
//This fails, as method is not availible for null.
d.function({return c.method();});
//This works but now I can't check whether c is null or not.
d.write(); //will fail.

Any suggestions?


Maybe you could rephrase your question in english.  I can't really  
understand what you are trying to do with this code.


i.e. "I want to be able to tell whether a delegate is null or not, how do  
I do that".  But you do that just like you said -- dg !is null.


-Steve


Re: delegate !is null

2009-09-04 Thread Saaa
D should be like this :)
class D
{
  private int delegate(void) _deleg;
  private int _value; //
  this(int delegate(void) d)
  {
_deleg = d;
  }
  void write()
  {
if(_deleg !is null)
}
  _value = _deleg(); //
}
writefln(_value); //
  }
} 




delegate !is null

2009-09-04 Thread Saaa
class C
{
  private int i;
  int method()
  {
return i;
  }
}

class D
{
  private int delegate(void) _deleg;
  this(int delegate(void) d)
  {
_deleg = d;
  }
  void write()
  {
if(_deleg !is null)
}
  writef(_deleg());
}
  }
}
C c = null;
D d = new d;
d.function(c.method());
//This fails, as method is not availible for null.
d.function({return c.method();});
//This works but now I can't check whether c is null or not.
d.write(); //will fail.

Any suggestions?