Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 11:25:40 UTC, Simen Kjærås wrote: I'm sorry, I was apparently unclear. When I said 'static array' above, I meant 'static member'. Since we've been using arrays in our examples, there could be conflation of ideas there. The fact that you can access (and even

Re: typedef behavior

2018-02-12 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 12 February 2018 at 09:58:13 UTC, Alex wrote: On Monday, 12 February 2018 at 09:37:56 UTC, Simen Kjærås wrote: Not really, since D doesn't have a concept of an address associated with a type, only with instances of it. So when you use a static array, the address is hard-coded.

Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 09:37:56 UTC, Simen Kjærås wrote: Not really, since D doesn't have a concept of an address associated with a type, only with instances of it. So when you use a static array, the address is hard-coded. -- Simen Ok... so the query on ptr on a static is not

Re: typedef behavior

2018-02-12 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 12 February 2018 at 09:10:52 UTC, Alex wrote: A more extreme example: You have a compiled library, and some .di (header) files. In one of those files is this code: struct S { static int[] arr; void foo(); } Now how should Typedef go about making foo() do the right thing?

Re: typedef behavior

2018-02-12 Thread Alex via Digitalmars-d-learn
On Monday, 12 February 2018 at 08:51:14 UTC, Simen Kjærås wrote: I agree that'd be nice. Sadly, it's not a reasonable expectation. :( :) A more extreme example: You have a compiled library, and some .di (header) files. In one of those files is this code: struct S { static int[] arr;

Re: typedef behavior

2018-02-12 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 11 February 2018 at 19:33:23 UTC, Alex wrote: On Sunday, 11 February 2018 at 15:18:11 UTC, Simen Kjærås wrote: Basically, Typedef looks like this: struct Typedef(T) { T _payload; // Forward method calls, member access, etc, to _payload. } If T looks like this: struct T {

Re: typedef behavior

2018-02-11 Thread Alex via Digitalmars-d-learn
On Sunday, 11 February 2018 at 15:18:11 UTC, Simen Kjærås wrote: Basically, Typedef looks like this: struct Typedef(T) { T _payload; // Forward method calls, member access, etc, to _payload. } If T looks like this: struct T { static int[3] arr; void foo() { arr[0]++; } } How

Re: typedef behavior

2018-02-11 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 11 February 2018 at 01:32:52 UTC, Alex wrote: On Saturday, 10 February 2018 at 02:55:26 UTC, Alex wrote: bug filed https://issues.dlang.org/show_bug.cgi?id=18416 Basically, Typedef looks like this: struct Typedef(T) { T _payload; // Forward method calls, member access,

Re: typedef behavior

2018-02-10 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 02:55:26 UTC, Alex wrote: bug filed https://issues.dlang.org/show_bug.cgi?id=18416

Re: typedef behavior with @disable this()

2018-02-10 Thread Alex via Digitalmars-d-learn
On Sunday, 11 February 2018 at 00:54:07 UTC, Simen Kjærås wrote: Typedef explicitly initializes the wrapped value to T.init, thus circumventing the disabled default constructor. Filed a bug: https://issues.dlang.org/show_bug.cgi?id=18415 -- Simen Thanks!

Re: typedef behavior with @disable this()

2018-02-10 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 10 February 2018 at 13:18:28 UTC, Alex wrote: Do I overlook something? /// --- code --- /// import std.typecons; void main(){} static assert(!__traits( compiles, E())); static assert(!__traits( compiles, MyE())); // line 6 struct E { size_t dummy; @disable

typedef behavior with @disable this()

2018-02-10 Thread Alex via Digitalmars-d-learn
Do I overlook something? /// --- code --- /// import std.typecons; void main(){} static assert(!__traits( compiles, E())); static assert(!__traits( compiles, MyE())); // line 6 struct E { size_t dummy; @disable this(); this(size_t val) { dummy = val; } } alias MyE =

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 02:08:50 UTC, Alex wrote: Inside of the struct E I define more then one static array. Namely, one for each Typedef I plan to instantiate. The Typedefs have to be known at compile time, so the amount of them has to be known by me :) Then, during the

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 01:23:20 UTC, Ali Çehreli wrote: > > Yup. They are shared by two Typedef instantiations with different cookies. > > So... > The question is two-fold: > Would it help to alter the init value of the Typedef? > If yes, how to alter it? > If no, is this a bug? I

Re: typedef behavior

2018-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 02/09/2018 05:14 PM, Alex wrote: >> > struct E >> > { >> > size_t i; >> > static T[] tarr; >> >> To save time to others, note that 'tarr' is a static member that ends >> up being shared by two Typedef instantiations. > > Yup. They are shared by two Typedef instantiations with

Re: typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
On Saturday, 10 February 2018 at 01:01:39 UTC, Ali Çehreli wrote: On 02/09/2018 03:45 PM, Alex wrote: > A question about Typedef usage: > Say, I have the following circumstances > > /// --- code --- /// > > import std.typecons; > > void main() > { > MyEA ea; > MyEB eb; >

Re: typedef behavior

2018-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 02/09/2018 03:45 PM, Alex wrote: > A question about Typedef usage: > Say, I have the following circumstances > > /// --- code --- /// > > import std.typecons; > > void main() > { > MyEA ea; > MyEB eb; > ea.tarr.length = 5; > static assert(!is(MyEA == MyEB)); > static

typedef behavior

2018-02-09 Thread Alex via Digitalmars-d-learn
A question about Typedef usage: Say, I have the following circumstances /// --- code --- /// import std.typecons; void main() { MyEA ea; MyEB eb; ea.tarr.length = 5; static assert(!is(MyEA == MyEB)); static assert(!is(MyEA == E)); static