funky property error with assoc array

2012-11-14 Thread Dan
This fails to compile when accessing as m.pgoo() complaining about postblit. What is wrong with this? Note: If I alias as array instead of map: alias const(X)[] Map; it compiles fine. Thanks Dan - struct X { this(this) {} } alias const(X)[string] Map; @property int

funky property error with assoc array

2012-11-14 Thread Dan
This fails to compile when accessing as m.pgoo() complaining about postblit. What is wrong with this? Note: If I alias as array instead of map: alias const(X)[] Map; it compiles fine. Thanks Dan - struct X { this(this) {} } alias const(X)[string] Map; @property int

funky property error with assoc array

2012-11-14 Thread Dan
This fails to compile when accessing as m.pgoo() complaining about postblit. What is wrong with this? Note: If I alias as array instead of map: alias const(X)[] Map; it compiles fine. Thanks Dan - struct X { this(this) {} } alias const(X)[string] Map; @property int

Re: Error: no property 'opCall' for type 'app1.ReturnContent'

2012-10-24 Thread Jonathan M Davis
On Wednesday, October 24, 2012 12:00:11 Suliman wrote: > import std.stdio; > > void main() > > { > ReturnContent(); > } > > > public class ReturnContent > { > void ReturnContent() > { > writeln("hello"); > } > } > > Why I am getting this error? > D2 It me

Error: no property 'opCall' for type 'app1.ReturnContent'

2012-10-24 Thread Suliman
import std.stdio; void main() { ReturnContent(); } public class ReturnContent { void ReturnContent() { writeln("hello"); } } Why I am getting this error? D2

Re: Returning reference to integer from property setter function

2012-10-16 Thread m0rph
Thanks for reply, hopefully this issue will be fixed sometime..

Re: Returning reference to integer from property setter function

2012-10-16 Thread Adam D. Ruppe
On Tuesday, 16 October 2012 at 14:43:09 UTC, m0rph wrote: Hi! How I can return from function a reference to int? The problem here isn't about the ref but rather the way properties are implemented with +=. I believe this is one of the older still-standing D bugs. It rewrites your expresssion

Returning reference to integer from property setter function

2012-10-16 Thread m0rph
Hi! How I can return from function a reference to int? Here is a simple code, to demonstrate my problem: struct Foo { public: @property int foo() const { return x_; } @property ref int foo(int value) { x_ = value

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 11:39:08 UTC, monarch_dodra wrote: Oh. I think I just got what your "reassign" was meant to do. I think I see it now. I guess it does work nice actually. I'd say that unfortunately, your *new* reassign is making the assumption that it is possible to grab a refe

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread monarch_dodra
a[1 .. $]); } } struct S { private int i; @property int x(){return i;} @property int x(int v){return i = v;} } void main() { S a = S(1); S b = S(2); S c = S(3); a.x = b.x; b.x = c.x; c.x = 4; writefln("%s %s %s", a.x, b.x, c.x); reassign(

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 07:00:37 UTC, monarch_dodra wrote: On Sunday, 23 September 2012 at 21:44:20 UTC, comco wrote: [SNIP] Now we can implement our rotate in terms of reassign: void rotate(node* u) { auto v = u.right; reassign(u.right, v.left, u); } This works and is g

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread monarch_dodra
On Sunday, 23 September 2012 at 21:44:20 UTC, comco wrote: [SNIP] Now we can implement our rotate in terms of reassign: void rotate(node* u) { auto v = u.right; reassign(u.right, v.left, u); } This works and is general enough, but notice the duplication of u.right. I don't l

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread comco
ng an "Error: need 'this' to access member x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? By using s.x, you're not referencing the property, but directly the value s.x, which is known only at runtime: it cannot be a tem

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread comco
x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? By using s.x, you're not referencing the property, but directly the value s.x, which is known only at runtime: it cannot be a template argument. If x where a static member, you could pro

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread Ali Çehreli
On 09/23/2012 11:49 AM, comco wrote: For this program I'm getting an "Error: need 'this' to access member x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? import std.stdio; mixin template T(alias a) { void f() { writeln

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread Philippe Sigaud
monarch_dodra already answered, but since, I typed this, I may as well post it :) On Sun, Sep 23, 2012 at 8:49 PM, comco wrote: > For this program I'm getting an "Error: need 'this' to access member x" at > line (*). Does that mean that we cannot alias a property

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread monarch_dodra
On Sunday, 23 September 2012 at 18:48:14 UTC, comco wrote: For this program I'm getting an "Error: need 'this' to access member x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? import std.stdio;

alias to a property as an argument to a mixin template

2012-09-23 Thread comco
For this program I'm getting an "Error: need 'this' to access member x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? import std.stdio; mixin template T(alias a) { void f(

Re: struct init property

2012-08-24 Thread Timon Gehr
On 08/24/2012 09:39 AM, nocide wrote: Am 23.08.2012 19:15, schrieb nocide: struct has no default constructor and instances are initialized with the init property. Can I declare or override the init property for a custom defined struct? Ok, the initializer forks fine for me, but I&#x

Re: struct init property

2012-08-24 Thread nocide
Am 23.08.2012 19:15, schrieb nocide: struct has no default constructor and instances are initialized with the init property. Can I declare or override the init property for a custom defined struct? Ok, the initializer forks fine for me, but I've encounterd following situation: (simpl

Re: struct init property

2012-08-23 Thread Ali Çehreli
On 08/23/2012 12:38 PM, Dmitry Olshansky wrote: On 23-Aug-12 23:33, Namespace wrote: But to write your own init property would still be nice, or not? Either way it has to be CTFEable. Can't you just do: struct A{ X field = generateX(); } and thus set .init to whatever you want. Otherwi

Re: struct init property

2012-08-23 Thread Namespace
:D I didn't know that, thanks.

Re: struct init property

2012-08-23 Thread Jonathan M Davis
On Friday, August 24, 2012 02:00:22 Namespace wrote: > > I would expect you to be able to do > > > > test(NotNullable!Foo(new Foo)); > > > > and with a helper function, you could have something like > > > > test(notNullable(new Foo)); > > > > - Jonathan M Davis > > But then you have an lvalue

Re: struct init property

2012-08-23 Thread Namespace
I would expect you to be able to do test(NotNullable!Foo(new Foo)); and with a helper function, you could have something like test(notNullable(new Foo)); - Jonathan M Davis But then you have an lvalue and cannot receive it as "ref NotNullable!Foo". Your struct would be copied with the (defa

Re: struct init property

2012-08-23 Thread Jonathan M Davis
On Friday, August 24, 2012 01:35:56 Namespace wrote: > > If you want something that isn't nullable, you'll need a type > > which which > > isn't nullable, which means using a struct. I know that you > > want non-nullable > > references, but for D2, the best that you're going to get is a > > struct

Re: struct init property

2012-08-23 Thread Namespace
If you want something that isn't nullable, you'll need a type which which isn't nullable, which means using a struct. I know that you want non-nullable references, but for D2, the best that you're going to get is a struct which wraps a class. - Jonathan M Davis That would be fine if i only h

Re: struct init property

2012-08-23 Thread Jonathan M Davis
On Thursday, August 23, 2012 23:27:18 Namespace wrote: > My idea was to declare your own .init in a class, not in a struct. Well, the init for classes will always be null, because class references are nullable. That's part of the language. Making it so that a class' init value wasn't guaranteed

Re: struct init property

2012-08-23 Thread Namespace
How would it be different from defining a default constructor? Structs specifically _don't_ have default constructors, because init must be known at compile time, and all kinds of restrictions would have to be placed on a default constructor (enough to make it pointless) to ensure that it would

Re: struct init property

2012-08-23 Thread Jonathan M Davis
On Thursday, August 23, 2012 21:33:57 Namespace wrote: > But to write your own init property would still be nice, or not? How would it be different from defining a default constructor? Structs specifically _don't_ have default constructors, because init must be known at compile time,

Re: struct init property

2012-08-23 Thread Namespace
But to write your own init property would still be nice, or not?

Re: struct init property

2012-08-23 Thread Dmitry Olshansky
On 23-Aug-12 23:33, Namespace wrote: But to write your own init property would still be nice, or not? Either way it has to be CTFEable. Can't you just do: struct A{ X field = generateX(); } and thus set .init to whatever you want. Otherwise it will inevitably rise question of the poi

Re: struct init property

2012-08-23 Thread Dmitry Olshansky
On 23-Aug-12 22:44, Namespace wrote: It would be great if you could declare your own .init as you can atm with "new" (http://dlang.org/class.html#allocators). Read on : Note: Class allocators are deprecated in D2. For example: class Foo { public: init() { this = new typeof(this

Re: struct init property

2012-08-23 Thread Namespace
It would be great if you could declare your own .init as you can atm with "new" (http://dlang.org/class.html#allocators). For example: class Foo { public: init() { this = new typeof(this)(); } } So you could avoid a null declaration by default. :)

Re: struct init property

2012-08-23 Thread Jonathan M Davis
On Thursday, August 23, 2012 19:15:16 nocide wrote: > struct has no default constructor and instances are initialized with the > init property. > Can I declare or override the init property for a custom defined struct? The init property is defined by what you directly initialize the

Re: struct init property

2012-08-23 Thread nocide
[snip] Ah thanks! You just were a little bit faster :)

Re: struct init property

2012-08-23 Thread nocide
Am 23.08.2012 19:15, schrieb nocide: struct has no default constructor and instances are initialized with the init property. Can I declare or override the init property for a custom defined struct? I've just realized, that I just have to declare default initializer for the members. This

Re: struct init property

2012-08-23 Thread Ali Çehreli
On 08/23/2012 10:15 AM, nocide wrote: struct has no default constructor and instances are initialized with the init property. Can I declare or override the init property for a custom defined struct? You can define the initial values of each member: struct S { int i = 42; double d

struct init property

2012-08-23 Thread nocide
struct has no default constructor and instances are initialized with the init property. Can I declare or override the init property for a custom defined struct?

Re: opCall() @property

2012-06-29 Thread Zhenya
On Friday, 29 June 2012 at 20:13:58 UTC, Jonathan M Davis wrote: On Friday, June 29, 2012 21:54:42 Zhenya wrote: I see, I just thought that opCall @ property equivalent opAssign and wanted to check it out, and now I would be interested to understand why it is not I don't see how you

Re: opCall() @property

2012-06-29 Thread Jonathan M Davis
On Friday, June 29, 2012 21:54:42 Zhenya wrote: > I see, I just thought that opCall @ property equivalent opAssign > and wanted to check it out, and now I would be interested to > understand why it is not I don't see how you could think that it _would_ be. The _only_ way that

Re: opCall() @property

2012-06-29 Thread Jonathan M Davis
On Friday, June 29, 2012 21:08:05 Zhenya wrote: > struct X > { > bool _x; > A opCall(bool x) @property {_x = x;return this;} > } > > void main() > { > X a; > x = false;//the same that x.opCall(false)? > } > > I thought that I could replace these opAssign,

Re: opCall() @property

2012-06-29 Thread Zhenya
On Friday, 29 June 2012 at 19:37:50 UTC, Namespace wrote: This works: import std.stdio; struct X { private: bool _x; public: this(bool x) { _x = x; } @property bool Get() inout { return this._x; } alias

Re: opCall() @property

2012-06-29 Thread Namespace
This works: import std.stdio; struct X { private: bool _x; public: this(bool x) { _x = x; } @property bool Get() inout { return this._x; } alias Get this; typeof(this) opAssign(bool x

opCall() @property

2012-06-29 Thread Zhenya
struct X { bool _x; A opCall(bool x) @property {_x = x;return this;} } void main() { X a; x = false;//the same that x.opCall(false)? } I thought that I could replace these opAssign, but the compiler does not agree with me. But why?

Re: property returning a reference vs returning a value

2012-06-20 Thread Jonathan M Davis
On Wednesday, June 20, 2012 09:03:44 cal wrote: > On Wednesday, 20 June 2012 at 06:34:06 UTC, Jonathan M Davis > > wrote: > > You can't overload on return type. The parameters need to be > > different, or the functions are going to conflict. > > Ah, that explains it, thanks. I find ref properties

Re: property returning a reference vs returning a value

2012-06-20 Thread cal
On Wednesday, 20 June 2012 at 06:34:06 UTC, Jonathan M Davis wrote: You can't overload on return type. The parameters need to be different, or the functions are going to conflict. Ah, that explains it, thanks. I find ref properties useful for making a member variable behave like it is public,

Re: property returning a reference vs returning a value

2012-06-19 Thread Jonathan M Davis
On Wednesday, June 20, 2012 05:42:25 cal wrote: > This doesn't compile, because the assignment matches both > property functions in S: > > struct S > { > @property int a() { return _a; } > @property ref int a() { return _a; } > int _a; > } > >

property returning a reference vs returning a value

2012-06-19 Thread cal
This doesn't compile, because the assignment matches both property functions in S: struct S { @property int a() { return _a; } @property ref int a() { return _a; } int _a; } int main() { S s; s.a = 5; } But I would like to be able to do different things when I pass

Re: alias this with property enforce

2012-06-06 Thread Kenji Hara
On Wednesday, 6 June 2012 at 18:12:39 UTC, Namespace wrote: If i have this code: class Bar { public: Foo GetFoo() { return this._foo; } alias GetFoo this; } to allow access to Foo methods from Bar i get the error, that "GetFoo" isn't a property if i use -prop

alias this with property enforce

2012-06-06 Thread Namespace
If i have this code: class Bar { public: Foo GetFoo() { return this._foo; } alias GetFoo this; } to allow access to Foo methods from Bar i get the error, that "GetFoo" isn't a property if i use -property. Why? The solution is to set @property before "Foo GetFoo()&quo

Re: Define .empty property for hashes?

2012-03-05 Thread Steven Schveighoffer
On Fri, 02 Mar 2012 16:21:00 -0500, Ali Çehreli wrote: On 03/02/2012 01:08 PM, Andrej Mitrovic wrote: > Is there a reason why there's no .empty property for hashes? std.array > defines it for arrays, and range types must have it defined. Yes, empty is a part of the InputRang

Re: Define .empty property for hashes?

2012-03-02 Thread Ali Çehreli
On 03/02/2012 01:08 PM, Andrej Mitrovic wrote: > Is there a reason why there's no .empty property for hashes? std.array > defines it for arrays, and range types must have it defined. Yes, empty is a part of the InputRange interface. Slices are InputRange ranges but associative arr

Define .empty property for hashes?

2012-03-02 Thread Andrej Mitrovic
Is there a reason why there's no .empty property for hashes? std.array defines it for arrays, and range types must have it defined. But hashes are left out even though they define .length. This could be put in std.array: @property bool empty(T)(in T a) if (isAssociativeArray!T) { r

Re: post/pre-increment/decrement and property

2012-02-07 Thread Jacob Carlborg
On 2012-02-08 01:50, Robert Clipsham wrote: On 07/02/2012 23:04, Timon Gehr wrote: Try this: int _foo; @property ref foo() { return _foo; } @property ref foo(int foo) { return _foo = foo; } void main() { ++foo; } Using 'ref' instead of auto returns a reference to _foo, allo

Re: post/pre-increment/decrement and property

2012-02-07 Thread Robert Clipsham
On 07/02/2012 23:04, Timon Gehr wrote: Try this: int _foo; @property ref foo() { return _foo; } @property ref foo(int foo) { return _foo = foo; } void main() { ++foo; } Using 'ref' instead of auto returns a reference to _foo, allowing it to be modified. Yes, but then

Re: post/pre-increment/decrement and property

2012-02-07 Thread Timon Gehr
On 02/07/2012 11:54 PM, Robert Clipsham wrote: On 07/02/2012 22:37, Vidar Wahlberg wrote: Take the following code: int _foo; @property auto foo() { return _foo; } @property auto foo(int foo) { return _foo = foo; } void main() { ++foo; } This won't compile, and it sort of makes sense (at

Re: post/pre-increment/decrement and property

2012-02-07 Thread Robert Clipsham
On 07/02/2012 22:37, Vidar Wahlberg wrote: Take the following code: int _foo; @property auto foo() { return _foo; } @property auto foo(int foo) { return _foo = foo; } void main() { ++foo; } This won't compile, and it sort of makes sense (at least to me), but is it (or will it in the futu

post/pre-increment/decrement and property

2012-02-07 Thread Vidar Wahlberg
Take the following code: int _foo; @property auto foo() { return _foo; } @property auto foo(int foo) { return _foo = foo; } void main() { ++foo; } This won't compile, and it sort of makes sense (at least to me), but is it (or will it in the future be) possib

question -property

2012-01-04 Thread sclytrack
.property = "test"; .method = "test"; .method("test"); What does -property exactly do? If you had like a dynamic where you don't know if it's member is a property or a method. You would choose method right? scratch the invalid ones below. ----

Re: Fields size property

2011-11-22 Thread Andrej Mitrovic
:) On 11/22/11, Dejan Lekic wrote: > > This one is not good either because it does not include TypeInfo, etc... > > __traits(classInstanceSize, T)) is better choice, as Ali said... :) >

Re: Fields size property

2011-11-22 Thread Dejan Lekic
This one is not good either because it does not include TypeInfo, etc... __traits(classInstanceSize, T)) is better choice, as Ali said... :)

Re: Fields size property

2011-11-18 Thread Dejan Lekic
Andrej Mitrovic wrote: > .sizeof on a struct works nicely since it's a POD, but this can't work > on classes since it just returns the pointer size. > > I don't know whether this is useful all that much, but I'm curious how > large my classes are. Anyway, since I couldn't find anything in Phobos

Make setMaxMailboxSize a property of a Tid?

2011-11-17 Thread Andrej Mitrovic
I've had this bug recently: auto workTid = spawn(&work); setMaxMailboxSize(thisTid, 1, OnCrowding.throwException); IOW, I've passed 'thisTid' instead of 'workTid' to the call. Is there any reason why had to be a global function? Tid has a private MessageBox which has the setMaxMsgs method. We ca

Re: Fields size property

2011-11-10 Thread Andrej Mitrovic
On 11/11/11, Ali Çehreli wrote: > This is the standard way: > > __traits(classInstanceSize, Foo) > > Ali > Thanks! It's also more reliable it seems. :)

Re: Fields size property

2011-11-10 Thread Ali Çehreli
On 11/10/2011 05:44 PM, Andrej Mitrovic wrote: .sizeof on a struct works nicely since it's a POD, but this can't work on classes since it just returns the pointer size. I don't know whether this is useful all that much, but I'm curious how large my classes are. Anyway, since I couldn't find anyt

Re: Fields size property

2011-11-10 Thread Andrej Mitrovic
On 11/11/11, Andrej Mitrovic wrote: > foreach (type; RepresentationTypeTuple!Foo) { Way to screw that up. Fix: foreach (type; RepresentationTypeTuple!T) {

Fields size property

2011-11-10 Thread Andrej Mitrovic
.sizeof on a struct works nicely since it's a POD, but this can't work on classes since it just returns the pointer size. I don't know whether this is useful all that much, but I'm curious how large my classes are. Anyway, since I couldn't find anything in Phobos I've got this working: import std

Re: AA clear property

2011-11-06 Thread Alex_Dovhal
Thakns for details. Arfer another small benchmark, it appeared that addition to AA is 10x times slower than removal from it. So that's why (2) isn't so bad in my previous tests - most of time AA was adding elements to remove later. Anyway if (2) also reallocates it's much much worse that (1).

Re: AA clear property

2011-11-06 Thread Jonathan M Davis
On Sunday, November 06, 2011 04:11:07 Jonathan M Davis wrote: > On Sunday, November 06, 2011 13:39:27 Alex_Dovhal wrote: > > "Marco Leise" wrote: > > > No way I heard of. You could delete the entries one by one. :D > > > I guess setting all references to null is the easiest way to 'clear' > > > an

Re: AA clear property

2011-11-06 Thread Jonathan M Davis
On Sunday, November 06, 2011 13:39:27 Alex_Dovhal wrote: > "Marco Leise" wrote: > > No way I heard of. You could delete the entries one by one. :D > > I guess setting all references to null is the easiest way to 'clear' an > > AA. > > Thanks. I tried both of them in small benchmark. Results are >

Re: AA clear property

2011-11-06 Thread Alex_Dovhal
"Marco Leise" wrote: > No way I heard of. You could delete the entries one by one. :D > I guess setting all references to null is the easiest way to 'clear' an > AA. Thanks. I tried both of them in small benchmark. Results are (1) fill_values(aa); aa = null (2) fill_values(aa); aa.remove(...) For

Re: AA clear property

2011-11-06 Thread Marco Leise
l function call", that matches the part before the dot with the first parameter of the function. This only works for arrays. So I believe it is a free function (to invalidate/finalize a variable) and not a property of an array at all. Thanks for clarification. So now my question and task change

Re: AA clear property

2011-11-05 Thread Alex_Dovhal
part before > the dot with the first parameter of the function. This only works for > arrays. So I believe it is a free function (to invalidate/finalize a > variable) and not a property of an array at all. Thanks for clarification. So now my question and task changes. Is there a way to r

Re: AA clear property

2011-11-05 Thread Marco Leise
Am 05.11.2011, 21:30 Uhr, schrieb Alex_Dovhal : Hi, D have "clear" property for arrays and AA, but I failed to find it's description in docs. Where it's? Are you this Alex? http://aichallenge.org/forums/viewtopic.php?f=21&t=1315#p10776 As I understand it this functi

AA clear property

2011-11-05 Thread Alex_Dovhal
Hi, D have "clear" property for arrays and AA, but I failed to find it's description in docs. Where it's?

Re: Dealing with property function and operator overloads

2011-10-04 Thread Andrej Mitrovic
Also I can use a forward function for toString, I didn't realize this until now: string toString() { return to!string(payload); }

Re: Dealing with property function and operator overloads

2011-10-04 Thread Andrej Mitrovic
On 10/4/11, Jacob Carlborg wrote: > No "alias this" in the wrapper? I shouldn't have named it Wrapper, you could better think of it as a Widget with a position field, if that position is changed (and not just read from) then some kind of repaint mechanism would be invoked. However I shouldn't in

Re: Dealing with property function and operator overloads

2011-10-03 Thread Jacob Carlborg
t; rhs;"); } } struct Wrapped(T) { T payload; alias payload this; void delegate() dg; @property void changed(void delegate() dg) { this.dg = dg; } void opOpAssign(string op)(int rhs) { payload.opOpAssign!op(rhs); dg();

Re: Dealing with property function and operator overloads

2011-10-03 Thread bearophile
Steven Schveighoffer: > I suspect operator overloads are going to be a large hole in the interface > design of many objects, but at least they won't be exploitable once > compiled. Just after the introduction of the new operator overload syntax I have suggested to introduce strict tests to s

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
On 10/3/11, Steven Schveighoffer wrote: > Even so, it's better for people who are not familiar with the language to > see correct code vs. code open to exploitation. I can see your point. I'll make some simple constraints when I post code samples like this from now on.

Re: Dealing with property function and operator overloads

2011-10-03 Thread Steven Schveighoffer
On Mon, 03 Oct 2011 16:07:19 -0400, Andrej Mitrovic wrote: On 10/3/11, Steven Schveighoffer wrote: Probably slightly off topic, but be very careful with operator overloads without using constraints. For example, I can do some weird things to your struct: Point p; p.opOpAssign!"*x; y+="(5

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
On 10/3/11, Steven Schveighoffer wrote: > Probably slightly off topic, but be very careful with operator overloads > without using constraints. > > For example, I can do some weird things to your struct: > > Point p; > > p.opOpAssign!"*x; y+="(5); > > I suspect operator overloads are going to be a

Re: Dealing with property function and operator overloads

2011-10-03 Thread Steven Schveighoffer
On Mon, 03 Oct 2011 14:57:33 -0400, Andrej Mitrovic wrote: Looks like I can use some D tricks for this: import std.stdio; struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin ("x = x " ~ op ~ " rhs;"); mixin ("y = y " ~ op ~ " rhs;"); } } P

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
Forgot to add an opAssign in Wrapped as well: void opAssign(T)(T rhs) { payload = rhs; dg(); } That takes care of assigning and ops that change the object's state.

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
{ T payload; alias payload this; void delegate() dg; @property void changed(void delegate() dg) { this.dg = dg; } void opOpAssign(string op)(int rhs) { payload.opOpAssign!op(rhs); dg(); } } struct Wrapper { this(int x) { poin

Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
Sample code: struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin("x = x " ~ op ~ " rhs;"); mixin("y = y " ~ op ~ " rhs;"); } } struct Wrapper { void notifyChanged() { } @property void point(Point

Re: property aliases to existing functions

2011-09-24 Thread Jonathan M Davis
On Sunday, September 25, 2011 00:00:33 Andrej Mitrovic wrote: > I'm guessing the following is an accepts-invalid bug: > > void test(int) {} > void main() { test = 4; } > > Anyway, if/when the above stops being legal I'd be nice if I could > create property function

property aliases to existing functions

2011-09-24 Thread Andrej Mitrovic
I'm guessing the following is an accepts-invalid bug: void test(int) {} void main() { test = 4; } Anyway, if/when the above stops being legal I'd be nice if I could create property functions using aliases. Something like this: struct Bar { int getFoo() { return 0; } void se

Re: with() statement doesn't want to work with property functions

2011-09-19 Thread Timon Gehr
ntrol how _bar is manipulated. I've lost the ability to use the with statement, which is a minor inconvenience. Is there a specific reason why with() should not be allowed to be used with property functions? This works fine: immutable Foo foo; with (foo) { } So I don't see why it sh

with() statement doesn't want to work with property functions

2011-09-19 Thread Andrej Mitrovic
to use the with statement, which is a minor inconvenience. Is there a specific reason why with() should not be allowed to be used with property functions? This works fine: immutable Foo foo; with (foo) { } So I don't see why it shouldn't work on property functions?

Re: Read property using std.stream.Stream.read

2011-08-13 Thread nrgyzer
== Auszug aus nrgyzer (nrgy...@gmail.com)'s Artikel > Hi guys, > I'm trying to read a property of a class like: > class MyClass { >private ubyte pToRead; >@property ubyte toRead() { return pToRead; } > } > ... > File f = new File(...); > MyClass

Read property using std.stream.Stream.read

2011-08-13 Thread nrgyzer
Hi guys, I'm trying to read a property of a class like: class MyClass { private ubyte pToRead; @property ubyte toRead() { return pToRead; } } ... File f = new File(...); MyClass c = new MyClass(); f.read(c.toRead); ... but when I compile my code, I always get: executable.

Re: The compiler can not find the property function.

2011-05-31 Thread choi heejo
Thanks for your detailed answer :)

Re: The compiler can not find the property function.

2011-05-30 Thread Jonathan M Davis
On 2011-05-30 08:54, choi heejo wrote: > Greeting. > > I tried to compile this code with DMD 2.053: > > @property bool isZero(float value) > { > return value < float.epsilon; > } > > void main() > { > 0.1f.isZero; > readln(); > } > > But th

Re: The compiler can not find the property function.

2011-05-30 Thread David Nadlinger
On 5/30/11 5:54 PM, choi heejo wrote: Greeting. I tried to compile this code with DMD 2.053: @property bool isZero(float value) { return value < float.epsilon; } void main() { 0.1f.isZero; readln(); } But the compiler said, no property 'isZero' for type 'float'. I

The compiler can not find the property function.

2011-05-30 Thread choi heejo
Greeting. I tried to compile this code with DMD 2.053: @property bool isZero(float value) { return value < float.epsilon; } void main() { 0.1f.isZero; readln(); } But the compiler said, no property 'isZero' for type 'float'. I cannot understand this error.

Re: @property ref foo() { ...} won't work...?

2011-03-02 Thread Magnus Lie Hetland
On 2011-03-01 13:20:18 +0100, Steven Schveighoffer said: On Tue, 01 Mar 2011 07:19:21 -0500, Lars T. Kyllingstad wrote: On Tue, 01 Mar 2011 12:25:30 +0100, Magnus Lie Hetland wrote: 2. How can I make r.front = foo work, when I only have r.front(), returning a ref (which seems like it is us

Re: @property ref foo() { ...} won't work...?

2011-03-01 Thread Steven Schveighoffer
On Tue, 01 Mar 2011 07:19:21 -0500, Lars T. Kyllingstad wrote: On Tue, 01 Mar 2011 12:25:30 +0100, Magnus Lie Hetland wrote: 2. How can I make r.front = foo work, when I only have r.front(), returning a ref (which seems like it is used in actual code)? I think this is a bug, but I'm not e

Re: @property ref foo() { ...} won't work...?

2011-03-01 Thread Lars T. Kyllingstad
On Tue, 01 Mar 2011 12:25:30 +0100, Magnus Lie Hetland wrote: > In Andrei's book, as well as in the Phobos source, there are property > getters that return refs, as in... > > @property ref T front() { > return _payload[0]; > } > > ... and code that uses

@property ref foo() { ...} won't work...?

2011-03-01 Thread Magnus Lie Hetland
In Andrei's book, as well as in the Phobos source, there are property getters that return refs, as in... @property ref T front() { return _payload[0]; } ... and code that uses this with simple assignments, such as: r.front = foo; For some reason, I can't get this to work

<    1   2   3   4   5   6   >