Re: Do @property attributes not allow postincrement operators

2019-04-13 Thread Jamie via Digitalmars-d-learn
On Sunday, 14 April 2019 at 02:11:52 UTC, Mike Franklin wrote: On Sunday, 14 April 2019 at 01:54:39 UTC, Jamie wrote: Do @property attributes not allow postincrement operators? ... It's a long standing issue (going on 7 years old) ... I plan on getting to it, but there are other pressing

Re: Do @property attributes not allow postincrement operators

2019-04-13 Thread Mike Franklin via Digitalmars-d-learn
On Sunday, 14 April 2019 at 01:54:39 UTC, Jamie wrote: Do @property attributes not allow postincrement operators? import std.stdio; struct Foo { @property bar() { return 10; } @property bar(int x) { writeln(x); } } void main() { Foo foo; writeln(foo.bar); // actually calls

Do @property attributes not allow postincrement operators

2019-04-13 Thread Jamie via Digitalmars-d-learn
Do @property attributes not allow postincrement operators? import std.stdio; struct Foo { @property bar() { return 10; } @property bar(int x) { writeln(x); } } void main() { Foo foo; writeln(foo.bar); // actually calls foo.bar(); foo.bar = 10; // calls foo.bar(10

Re: Compile time opAssign/@property constraints

2019-01-05 Thread Jacob Shtokolov via Digitalmars-d-learn
t it seems that I got the idea. So even if I'd write opAssign or @property as a template function, I won't be able to get their arguments at compile time because every template takes different set of arguments: for compile time and for run time. And due to the fact that D is callin

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 4, 2019 4:50:30 AM MST Jacob Shtokolov via Digitalmars-d- learn wrote: > On Friday, 4 January 2019 at 11:41:59 UTC, Simen Kjærås wrote: > > The thing is, compile-time tests like static if and static > > assert can only test values that are known at compile-time, and > > are for

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Mike Parker via Digitalmars-d-learn
``` @property val(T v) { static assert(v > 0); value = v; } ``` v is a run-time value, not available at compile time.

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Jacob Shtokolov via Digitalmars-d-learn
On Friday, 4 January 2019 at 11:45:24 UTC, Jacob Shtokolov wrote: Here is the simple example: https://run.dlang.io/gist/1a06dd703bea5548ee72b4713a7ce5f6 Sorry, invalid link. Here is a new one: https://run.dlang.io/is/QZ5hLV

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Jacob Shtokolov via Digitalmars-d-learn
On Friday, 4 January 2019 at 11:41:59 UTC, Simen Kjærås wrote: The thing is, compile-time tests like static if and static assert can only test values that are known at compile-time, and are for the most part useful only in templates. Thanks for this answer! That's sad to hear. But, is there

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 January 2019 at 11:45:24 UTC, Jacob Shtokolov wrote: On Friday, 4 January 2019 at 10:34:07 UTC, Basile.B wrote: Show us some code. Here is the simple example: https://run.dlang.io/gist/1a06dd703bea5548ee72b4713a7ce5f6 The thing I'm trying to do is to make an experimental port

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Jacob Shtokolov via Digitalmars-d-learn
On Friday, 4 January 2019 at 10:34:07 UTC, Basile.B wrote: Show us some code. Here is the simple example: https://run.dlang.io/gist/1a06dd703bea5548ee72b4713a7ce5f6 The thing I'm trying to do is to make an experimental port (for education purposes) of https://github.com/fthomas/refined

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 4 January 2019 at 09:54:25 UTC, Jacob Shtokolov wrote: Hi, I'd like to implement some compile time constraints for a struct (though not sure if that's possible). I already tried to place "static assert" or any kind of static condition into a body of @property an

Re: Compile time opAssign/@property constraints

2019-01-04 Thread Basile.B via Digitalmars-d-learn
On Friday, 4 January 2019 at 09:54:25 UTC, Jacob Shtokolov wrote: Hi, I'd like to implement some compile time constraints for a struct (though not sure if that's possible). I already tried to place "static assert" or any kind of static condition into a body of @property an

Compile time opAssign/@property constraints

2019-01-04 Thread Jacob Shtokolov via Digitalmars-d-learn
Hi, I'd like to implement some compile time constraints for a struct (though not sure if that's possible). I already tried to place "static assert" or any kind of static condition into a body of @property and opAssign(), but every time it shows the error "variable cannot be

Re: property += operator

2018-05-10 Thread Mike Franklin via Digitalmars-d-learn
of the language) to make a library implementation more appealing. IMO, it'd be great if we could add more composable primitives to the language, and get rid of quirky features like @property. Mike

Re: property += operator

2018-05-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 10, 2018 18:43:40 SrMordred via Digitalmars-d-learn wrote: > struct T > { > int x; > @property ref X(){ return x; } > @property X(int v) > { > x = v; > } > } > > T t; > t.X += 10; > > The setter 'x =

Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn
On 5/10/2018 3:18 PM, Ali Çehreli wrote: On 05/10/2018 01:03 PM, Dlang User wrote: >> this didn´t work either. >> note that 'f.data+= 2;' don't call the write property > > That's odd, it works on my machine (Windows 10 with V2.079.0 DMD compiler). Try putting w

Re: property += operator

2018-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 05/10/2018 01:03 PM, Dlang User wrote: >> this didn´t work either. >> note that 'f.data+= 2;' don't call the write property > > That's odd, it works on my machine (Windows 10 with V2.079.0 DMD compiler). Try putting writeln expressions in the two functions to see whic

Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn
On 5/10/2018 2:50 PM, SrMordred wrote: On Thursday, 10 May 2018 at 19:41:41 UTC, Dlang User wrote: On 5/10/2018 1:43 PM, SrMordred wrote: [...] I am relatively new to D and I was under the impression that that was a limitation of @property functions. But, re-reading the language reference

Re: property += operator

2018-05-10 Thread SrMordred via Digitalmars-d-learn
On Thursday, 10 May 2018 at 19:41:41 UTC, Dlang User wrote: On 5/10/2018 1:43 PM, SrMordred wrote: [...] I am relatively new to D and I was under the impression that that was a limitation of @property functions. But, re-reading the language reference, it gave this example (it returns

Re: property += operator

2018-05-10 Thread Dlang User via Digitalmars-d-learn
On 5/10/2018 1:43 PM, SrMordred wrote: struct T {     int x;     @property ref X(){ return x; }     @property X(int v)     {     x = v;     } } T t; t.X += 10; The setter 'x = v' are not executed because i´m returning the reference of x. And without the 'ref' the compiler complains

property += operator

2018-05-10 Thread SrMordred via Digitalmars-d-learn
struct T { int x; @property ref X(){ return x; } @property X(int v) { x = v; } } T t; t.X += 10; The setter 'x = v' are not executed because i´m returning the reference of x. And without the 'ref' the compiler complains because 'x' is not a lvalue. Any solution

Re: Add property-like Function to Type ?

2018-04-24 Thread Meta via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 21:36:19 UTC, Rubn wrote: I was wondering if I could create my own property in a way that can be used the same way as something like "T.sizeof". Right now I have the following to replace length: uint length32(T)(T[] array) { return cast(uint)array.le

Re: Add property-like Function to Type ?

2018-04-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 24, 2018 21:36:19 Rubn via Digitalmars-d-learn wrote: > I was wondering if I could create my own property in a way that > can be used the same way as something like "T.sizeof". Right now > I have the following to replace length: > > uint length32(T)(T[]

Add property-like Function to Type ?

2018-04-24 Thread Rubn via Digitalmars-d-learn
I was wondering if I could create my own property in a way that can be used the same way as something like "T.sizeof". Right now I have the following to replace length: uint length32(T)(T[] array) { return cast(uint)array.length; } I want something similar to be able to do the

Re: Range length property

2018-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
löw wrote: >> Should ranges always provide a length property? > > No. > >> If so, in which cases is a length property an advantage or >> a requirement? > > Just provide it whenever it is cheap to do so. If you need > to do complex calculations or especi

Re: Range length property

2018-04-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 10, 2018 at 10:07:40PM +, Cym13 via Digitalmars-d-learn wrote: [...] > On the other hand I don't think the end user should have to scratch > his head to find the length of a range, especially if it's not trivial > to get (say, O(log n) kind of case). Therefore exposing a method in

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
34:40 UTC, Adam D. Ruppe wrote: > >> > On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: > >> >> Should ranges always provide a length property? > >> > > >> > No. > >> > > >> >> If so, in which cases is a length

Re: Range length property

2018-04-10 Thread Cym13 via Digitalmars-d-learn
es always provide a length property? > > No. > >> If so, in which cases is a length property an advantage or >> a requirement? > > Just provide it whenever it is cheap to do so. If you need > to do complex calculations or especially loop over contents >

Re: Range length property

2018-04-10 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 20:16:18 UTC, Steven Schveighoffer wrote: e.g. std.array.array is going to pre-allocate an array of the correct length and fill it in, vs. appending each element as it gets them from the range. Personally, I would store the length because typically a container

Re: Range length property

2018-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/10/18 4:08 PM, Jonathan M Davis wrote: On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: I'm thinking of my own container Hashmap having its range ByKeyValue requiring one extra word of memory to store the iteration count which, in turn, can be used to calculate

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: > On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: > > On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: > >> Should ranges always provide a length property? > > > > No.

Re: Range length property

2018-04-10 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: Should ranges always provide a length property? No. If so, in which cases is a length property an advantage or a requirement? Just provide it whenever it is cheap

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 14:25:52 Nordlöw via Digitalmars-d-learn wrote: > Should ranges always provide a length property? > > If so, in which cases is a length property an advantage or a > requirement? Whether a range has a length property or not is primarily dependent on h

Re: Range length property

2018-04-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: Should ranges always provide a length property? No. If so, in which cases is a length property an advantage or a requirement? Just provide it whenever it is cheap to do so. If you need to do complex calculations or especially loop

Range length property

2018-04-10 Thread Nordlöw via Digitalmars-d-learn
Should ranges always provide a length property? If so, in which cases is a length property an advantage or a requirement?

Re: @property for simple methods?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
that part. Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? Yes I would omit @proporty if you don't need it as it isn't really useful at the moment. There's a DIP to fix it and make it more powerful thou

Re: @property for simple methods?

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 2 April 2018 at 15:15:05 UTC, Dennis wrote: On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? You're probably fine either way, i

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? You're probably fine either way, it's mostly for making your intention clear. Jonathan M Davis ma

Re: @property for simple methods?

2018-04-02 Thread Seb via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote: On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag

Re: @property for simple methods?

2018-04-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote: On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag does can be found here: https://dlang.org/spec/function.html

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag does can be found here: https://dlang.org/spec/function.html#property-functions This behavior is particularly useful

@property for simple methods?

2018-04-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
Heyo. I have a struct with a couple "property" methods, like: struct A { auto foo(int bar) { /* do something */ } } Is there any reason for me to add the @property tags for the method? The following code compiles just fine with the struct above A a = A();

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 13:04:54 UTC, Simen Kjærås wrote: On Monday, 12 March 2018 at 10:37:00 UTC, Alex wrote: Sure, you have. https://dlang.org/spec/struct.html#assign-overload Point #4. In this case, ref S opAssign(ref S rhs) { return this; } True. Can you fix these, too? struct

Re: Generic Property Implementation

2018-03-12 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 12 March 2018 at 10:37:00 UTC, Alex wrote: Sure, you have. https://dlang.org/spec/struct.html#assign-overload Point #4. In this case, ref S opAssign(ref S rhs) { return this; } True. Can you fix these, too? struct S { S* ptr; this(int dummy) { ptr = }

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 09:54:20 UTC, Simen Kjærås wrote: But I don't have a hook to update the pointer when the struct is moved. The GC may move my struct without informing me in any way. In fact, even just a copy construction will break this: struct S { S* ptr; this(int dummy)

Re: Generic Property Implementation

2018-03-12 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 12 March 2018 at 08:59:49 UTC, Alex wrote: An incomplete type is perfectly ok, so there should be no problem with a pointer of the same type inside a struct. If accidentally the pointer refers "this", then it must have been set after construction. As before construction the value of

Re: Generic Property Implementation

2018-03-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 March 2018 at 07:04:19 UTC, Simen Kjærås wrote: On Saturday, 10 March 2018 at 17:43:06 UTC, Simen Kjærås wrote: I'm not sure how fixable this is, but I am sure that there's plenty of benefit to being able to write code like this: struct S { int n, m; SomeType!(() => n +

Re: Generic Property Implementation

2018-03-12 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 10 March 2018 at 17:43:06 UTC, Simen Kjærås wrote: I'm not sure how fixable this is, but I am sure that there's plenty of benefit to being able to write code like this: struct S { int n, m; SomeType!(() => n + m) a; } over this: struct S { int n, m; auto a() {

Re: Generic Property Implementation

2018-03-10 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 9 March 2018 at 23:34:56 UTC, Mike Franklin wrote: On Friday, 9 March 2018 at 14:46:04 UTC, Simen Kjærås wrote: 1) Wrong return type: unittest { S s; auto a = s.field; // Fails - typeof(a) is Property!((get) => this.n, (set) => this.n = set) assert(is(

Re: Generic Property Implementation

2018-03-09 Thread Mike Franklin via Digitalmars-d-learn
On Friday, 9 March 2018 at 14:46:04 UTC, Simen Kjærås wrote: This is the best I've come up with in the current language: struct S { int n; mixin property!("field", "get => this.n", "set => this.n = set"); } Not bad. Not good, but not bad either.

Re: Generic Property Implementation

2018-03-09 Thread Simen Kjærås via Digitalmars-d-learn
be scalable to data that isn't addressable (e.g. bitfields). See https://issues.dlang.org/show_bug.cgi?id=16187 This is the best I've come up with in the current language: struct S { int n; mixin property!("field", "get => this.n", "set => this.n = set")

Re: Generic Property Implementation

2018-03-08 Thread Mike Franklin via Digitalmars-d-learn
On Friday, 9 March 2018 at 01:22:15 UTC, Mike Franklin wrote: I would like to know if this can be improved to support the following: * binary assignment operators (e.g. +=) * unary assignment operators (e.g. ++) * @safe, @nogc, and -betterC compatible * at least as good code generation as

Re: Generic Property Implementation

2018-03-08 Thread Mike Franklin via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 14:34:53 UTC, bauss wrote: Would there be a reason why this wouldn't be a good implementation? If so what and how could it be improved? Are there flaws in an implementation like this? [... snip ...] I am very interested in this as a potential alternative to

Re: Generic Property Implementation

2018-02-20 Thread Simen Kjærås via Digitalmars-d-learn
ght of many more corner cases than you have. There is an argument to be made for compile-time overhead, I guess. So, my version of the same: struct Property(T, bool readOnly = false) { private T _value; static if (readOnly) T __GET() { return _value; } else

Generic Property Implementation

2018-02-20 Thread bauss via Digitalmars-d-learn
Would there be a reason why this wouldn't be a good implementation? If so what and how could it be improved? Are there flaws in an implementation like this? struct Property(T, bool readOnly = false) { import std.traits : isScalarType, isArray, isAssociativeArray, isSomeString

Re: `Alias this` to a mixed in property

2018-01-24 Thread Bastiaan Veelo via Digitalmars-d-learn
identifiers poses an extra challenge. I may go for string mixin's instead, which I just discovered do work: ``` import std.stdio; enum getter = ` @property int p() { writeln(__LINE__, " mixin getter"); return 3; } `; string setter(string T) pur

Re: `Alias this` to a mixed in property

2018-01-24 Thread ag0aep6g via Digitalmars-d-learn
On 01/24/2018 02:24 PM, Bastiaan Veelo wrote: `Alias this` to mixed in properties does not seem to work, see below. If you think it should, I'll file an issue. Otherwise: can this be made to work somehow? Not supposed to work as it is. The spec says that you cannot make an overload set just

`Alias this` to a mixed in property

2018-01-24 Thread Bastiaan Veelo via Digitalmars-d-learn
`, then the remaining property works. Does the compiler detect identical names and then does some additional mangling which messes with my `alias this` maybe? ``` import std.stdio; // version = manual; // Manually written property works, obviously. mixin template getter() { @property int p

Re: why @property cannot be pass as ref ?

2018-01-03 Thread ChangLong via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 08:51:55 UTC, Simen Kjærås wrote: On Saturday, 30 December 2017 at 03:49:37 UTC, ChangLong wrote: What I am try to do is implement a unique data type. (the ownership auto moved into new handle) Have you considered std.typecons.Unique[0]? If yes, in what ways

Re: why @property cannot be pass as ref ?

2018-01-03 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 30 December 2017 at 03:49:37 UTC, ChangLong wrote: What I am try to do is implement a unique data type. (the ownership auto moved into new handle) Have you considered std.typecons.Unique[0]? If yes, in what ways does it not cover your needs? Your example code written with

Re: why @property cannot be pass as ref ?

2018-01-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/29/2017 07:49 PM, ChangLong wrote: On Wednesday, 20 December 2017 at 18:43:21 UTC, Ali Çehreli wrote: Thanks to Mengü for linking to that section. I have to make corrections below. Ali Thanks for explain, Ali And Mengu. What I am try to do is implement a unique data type. (the

Re: why @property cannot be pass as ref ?

2017-12-29 Thread ChangLong via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 18:43:21 UTC, Ali Çehreli wrote: Thanks to Mengü for linking to that section. I have to make corrections below. Ali Thanks for explain, Ali And Mengu. What I am try to do is implement a unique data type. (the ownership auto moved into new handle)

Re: why @property cannot be pass as ref ?

2017-12-20 Thread Ali Çehreli via Digitalmars-d-learn
Thanks to Mengü for linking to that section. I have to make corrections below. On 12/20/2017 10:04 AM, Ali Çehreli wrote: > 'auto ref' essentially generates two copies of the function: one taking > by-value for rvalues Note that by-value for rvalues means "blitting" in D (blit: bit-level

Re: why @property cannot be pass as ref ?

2017-12-20 Thread Mengu via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 18:04:57 UTC, Ali Çehreli wrote: On 12/20/2017 07:02 AM, ChangLong wrote: > [...] is not > [...] The problem is not with opAssign but with left(), which returns an rvalue. It's by design that rvalues cannot be bound to references in D. [...] was just

Re: why @property cannot be pass as ref ?

2017-12-20 Thread Ali Çehreli via Digitalmars-d-learn
On 12/20/2017 07:02 AM, ChangLong wrote: > === > struct A { > alias This= typeof(this) ; > > void opAssign(ref This ){ > } > > ref auto left(){ > return This() ; > } > } > > void main(){ > Aroot ; > ref find() { >

why @property cannot be pass as ref ?

2017-12-20 Thread ChangLong via Digitalmars-d-learn
=== struct A { alias This = typeof(this) ; void opAssign(ref This ){ } ref auto left(){ return This() ; } } void main(){ A root ;

Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Thursday, 9 November 2017 at 14:34:10 UTC, Steven Schveighoffer wrote: On 11/9/17 7:34 AM, Timoses wrote: I suppose this is what Adam suggested, correct? Yes, more or less. It's just an actual implementation vs. a description in case it wasn't clear. [...] It's not much different

Re: Distinct "static" parent property contents for children

2017-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/9/17 7:34 AM, Timoses wrote: I suppose this is what Adam suggested, correct? Yes, more or less. It's just an actual implementation vs. a description in case it wasn't clear. This is a more general question: Why is it not possible to implement/override static methods? Static

Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 18:33:15 UTC, Steven Schveighoffer wrote: On 11/8/17 12:38 PM, Timoses wrote: Hey, wrapping my head around this atm.. [snip] so what you want is a static variable per subclass, but that the base class can access. What I would recommend is this: abstract

Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 17:46:42 UTC, Adam D. Ruppe wrote: On Wednesday, 8 November 2017 at 17:38:27 UTC, Timoses wrote: Are there better options/ways of achieving this? What are you actually trying to achieve? What are you using these variables for? Well, I have the following

Re: Distinct "static" parent property contents for children

2017-11-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/8/17 12:38 PM, Timoses wrote: Hey, wrapping my head around this atm.. [snip] so what you want is a static variable per subclass, but that the base class can access. What I would recommend is this: abstract class Base { int x(); } class A : Base { private static int _x = 1;

Re: Distinct "static" parent property contents for children

2017-11-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 17:38:27 UTC, Timoses wrote: Are there better options/ways of achieving this? What are you actually trying to achieve? What are you using these variables for? My first thought is you should abandon the variable approach and just use an abstract function

Re: Distinct "static" parent property contents for children

2017-11-08 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 17:38:27 UTC, Timoses wrote: Option 2: class Base { int x;} class A : Base { this() { x = 1; } } class B : Base { this() { x = 2; } } Con: Well, the downside is that every instance of A and B allocates space for x although only one allocation would be

Distinct "static" parent property contents for children

2017-11-08 Thread Timoses via Digitalmars-d-learn
Hey, wrapping my head around this atm.. How would I achieve that children statically set a property of the parent so that the property is distinct between different children? The following is *bs*, but kind of illustrates what I'd "like": class Base { int x; } clas

Re: @property with 2 arguments

2017-10-01 Thread Tony via Digitalmars-d-learn
On Sunday, 1 October 2017 at 07:11:14 UTC, bitwise wrote: On Sunday, 1 October 2017 at 05:57:53 UTC, Tony wrote: "@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the synt

Re: @property with 2 arguments

2017-10-01 Thread Tony via Digitalmars-d-learn
On Sunday, 1 October 2017 at 06:34:56 UTC, Jonathan M Davis wrote: On Sunday, October 01, 2017 05:57:53 Tony via Digitalmars-d-learn wrote: "@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two

Re: @property with 2 arguments

2017-10-01 Thread bitwise via Digitalmars-d-learn
On Sunday, 1 October 2017 at 05:57:53 UTC, Tony wrote: "@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the syntax for how it is accessed without (). And also this, which probably

Re: @property with 2 arguments

2017-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 01, 2017 05:57:53 Tony via Digitalmars-d-learn wrote: > "@property functions can only have zero, one or two parameters" > > I am looking for an example of an @property function defined with > two parameters and the syntax for how it is accessed with

@property with 2 arguments

2017-10-01 Thread Tony via Digitalmars-d-learn
"@property functions can only have zero, one or two parameters" I am looking for an example of an @property function defined with two parameters and the syntax for how it is accessed without ().

Re: generating @property from structs

2017-09-30 Thread user1234 via Digitalmars-d-learn
On Saturday, 30 September 2017 at 08:20:44 UTC, Nicholas Wilson wrote: struct MyType { void* ptr; static struct Info { @(42) int foo; } // Should be generated by the mixin below @property int foo() { int ret; getMyTypeInfo(ptr,42,int.sizeof

generating @property from structs

2017-09-30 Thread Nicholas Wilson via Digitalmars-d-learn
struct MyType { void* ptr; static struct Info { @(42) int foo; } // Should be generated by the mixin below @property int foo() { int ret; getMyTypeInfo(ptr,42,int.sizeof,); return ret; } mixin generateInfo!getMyTypeInfo

Re: gtk: get property

2017-08-05 Thread Johnson Jones via Digitalmars-d-learn
On Saturday, 5 August 2017 at 15:19:43 UTC, Gerald wrote: On Saturday, 5 August 2017 at 15:08:21 UTC, Johnson Jones wrote: I am trying to get the handle size of panned. Not sure if I'm doing it right but [...] I'm using this in Tilix: Value handleSize = new Value(0);

Re: gtk: get property

2017-08-05 Thread Gerald via Digitalmars-d-learn
On Saturday, 5 August 2017 at 15:08:21 UTC, Johnson Jones wrote: I am trying to get the handle size of panned. Not sure if I'm doing it right but [...] I'm using this in Tilix: Value handleSize = new Value(0); paned.styleGetProperty("handle-size", handleSize);

gtk: get property

2017-08-05 Thread Johnson Jones via Digitalmars-d-learn
ct-WARNING **: g_object_get_property: object class 'GtkStyle' has no property named 'handle-size' if I do mainPaned.getStyle().getProperty("handle-size", value); I haven't been able to figure out how to get it. I've also tried mainPaned.getStyle().getStyleProperty(... but the first parame

Re: I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-26 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 26 July 2017 at 16:27:57 UTC, WhatMeWorry wrote: On Wednesday, 26 July 2017 at 02:31:33 UTC, Mike Parker wrote: With static arrays, the memory for the elements if part of the array itself, so it is counted in the size. For dynamic arrays, it is not. For .sizeof to report the

Re: I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-26 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 26 July 2017 at 02:32:07 UTC, Adam D. Ruppe wrote: I've hand rolled a function which is working for me currently, but with my coding ability, I'd feel much safer with something official :) You could also do (cast(ubyte[]) array).length. This was my (way over complicated)

Re: I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-26 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 26 July 2017 at 02:31:33 UTC, Mike Parker wrote: On Wednesday, 26 July 2017 at 02:24:06 UTC, WhatMeForget wrote: [...] Because .sizeof has nothing to do with how many elements are in the array. It tells you how much space the array itself takes up. Totally agree. .length

Re: I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 26 July 2017 at 02:24:06 UTC, WhatMeForget wrote: Static Arrays have property .sizeof which returns the array length multiplied by the number of bytes per array element. Dynamic Arrays have property .sizeof which returns the size of the dynamic array reference, which is 8 in 32

Re: I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-25 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 26 July 2017 at 02:24:06 UTC, WhatMeForget wrote: Static Arrays have property .sizeof which returns the array length multiplied by the number of bytes per array element. Dynamic Arrays have property .sizeof which returns the size of the dynamic array reference, which is 8 in 32

I feel the dynamic array .sizeof property is kind of a bait and switch

2017-07-25 Thread WhatMeForget via Digitalmars-d-learn
Static Arrays have property .sizeof which returns the array length multiplied by the number of bytes per array element. Dynamic Arrays have property .sizeof which returns the size of the dynamic array reference, which is 8 in 32-bit builds and 16 on 64-bit builds. Why not have dynamic

Re: Add property setting to chain

2017-07-16 Thread closescreen via Digitalmars-d-learn
Thanks for reply, Ali.

Re: Add property setting to chain

2017-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2017 12:53 PM, closescreen wrote: Let i have code: Clock.currTime.to!DateTime.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln; Now if i want to set the minute=0 and second=0 without breaking chain, what i should do? I think about somewhat like: with(

Re: Add property setting to chain

2017-07-15 Thread closescreen via Digitalmars-d-learn
I found this solution: Clock.currTime.to!DateTime.pipe!( dt=>(dt.minute=0,dt.second=0, dt) ).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln; Or: Clock.currTime.to!DateTime.pipe!( "a.minute=0, a.second=0, a" ).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;

Add property setting to chain

2017-07-15 Thread closescreen via Digitalmars-d-learn
Let i have code: Clock.currTime.to!DateTime.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln; Now if i want to set the minute=0 and second=0 without breaking chain, what i should do? I think about somewhat like: with( Clock.currTime.to!DateTime){ minute=0; second=0

Re: struct File. property size.

2017-05-11 Thread AntonSotov via Digitalmars-d-learn
On Thursday, 11 May 2017 at 08:42:26 UTC, Nicholas Wilson wrote: Are you in windows perchance? IIRC the when compiling for 32 bit it doesn't use the 64 bit C file function so that will not work. Yes, windows. Ok, I understood you.

Re: struct File. property size.

2017-05-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 11 May 2017 at 07:24:00 UTC, AntonSotov wrote: import std.stdio; int main() { auto big = File("bigfile", "r+"); //bigfile size 20 GB writeln(big.size); // ERROR! return 0; } // std.exception.ErrnoException@std\stdio.d(1029): Could

Re: struct File. property size.

2017-05-11 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 11 May 2017 at 07:24:00 UTC, AntonSotov wrote: import std.stdio; int main() { auto big = File("bigfile", "r+"); //bigfile size 20 GB writeln(big.size); // ERROR! return 0; } // std.exception.ErrnoException@std\stdio.d(1029): Could

struct File. property size.

2017-05-11 Thread AntonSotov via Digitalmars-d-learn
import std.stdio; int main() { auto big = File("bigfile", "r+"); //bigfile size 20 GB writeln(big.size); // ERROR! return 0; } // std.exception.ErrnoException@std\stdio.d(1029): Could not seek in file `bigfile` (Invalid argument) I can not

Re: Override @property

2017-05-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 16:40:09 UTC, Aldo wrote: class PictureBox : Control { @property public override void texture(Texture value) { writeln("override"); this.m_texture = value; } } Error: function f340.PictureB

Override @property

2017-05-10 Thread Aldo via Digitalmars-d-learn
Hello, can you tell me if this compilation error is normal ? class Texture { public this() { } } class Control { private Texture m_texture; @property { public Texture texture

<    1   2   3   4   5   6   >