Re: 'auto' with AA

2014-04-28 Thread David Held via Digitalmars-d-learn
On 4/27/2014 9:32 PM, Ali Çehreli wrote: fOn 04/27/2014 06:00 PM, David Held wrote: > I would like to do something like this: > > Foo[Bar][Baz] nestedAA; > auto innerAA = nestedAA[someBaz]; > innerAA[someBar] = someFoo; > assert(someFoo in nestedAA[someBaz]); in operator uses a key, not a

Is this a bug?

2014-04-28 Thread Andrey via Digitalmars-d-learn
Could anyone please explain to me, why do I have error message on this piece of code? alias short Type1; alias Type1[100]* Type2; // pointer to an array struct Type3 { Type2 f } void foo() { Type3* b; Type1 d; d = b.f[10]; // compilation error: cannot implicitly convert expres

Re: Is this a bug?

2014-04-28 Thread John Colvin via Digitalmars-d-learn
On Monday, 28 April 2014 at 08:58:41 UTC, Andrey wrote: Could anyone please explain to me, why do I have error message on this piece of code? alias short Type1; alias Type1[100]* Type2; // pointer to an array struct Type3 { Type2 f } void foo() { Type3* b; Type1 d; d = b.f[10]

Re: Is this a bug?

2014-04-28 Thread Andrey via Digitalmars-d-learn
not a bug. b.f[10] is indexing the pointer to the array, not the array itself. b.f[0][10] is indexing the array (with the 10), but I would argue it is better to write *(b.f)[10] so as to be clear that f is not an array. thank you, John. compiler said that '*(b.f)[10]' is deprecated, and I

Re: Is this a bug?

2014-04-28 Thread John Colvin via Digitalmars-d-learn
On Monday, 28 April 2014 at 09:36:08 UTC, Andrey wrote: not a bug. b.f[10] is indexing the pointer to the array, not the array itself. b.f[0][10] is indexing the array (with the 10), but I would argue it is better to write *(b.f)[10] so as to be clear that f is not an array. thank you, Jo

Re: Is this a bug?

2014-04-28 Thread bearophile via Digitalmars-d-learn
Andrey: Could anyone please explain to me, why do I have error message on this piece of code? In this thread you are doing some mistakes. This code seems OK: alias TData = short; alias TArray = TData[100]; struct MyStruct { TArray* arrPtr; } void main() { MyStruct* t3 = new MyStruct

Pointer to template types?

2014-04-28 Thread Chris via Digitalmars-d-learn
I need an array that contains pointers to types created via template. To stick to my usual example: Person!(string) How can I make an array with pointers to concrete "instances" of Person!(string)? Something like this only with pointers, i.e. buf holds pointers to concrete Person!(string)s:

Re: Pointer to template types?

2014-04-28 Thread bearophile via Digitalmars-d-learn
Chris: I need an array that contains pointers to types created via template. To stick to my usual example: Person!(string) How can I make an array with pointers to concrete "instances" of Person!(string)? Every template creates a new type, so you can't put them as they are in an array. Th

Re: Pointer to template types?

2014-04-28 Thread Chris via Digitalmars-d-learn
On Monday, 28 April 2014 at 10:32:18 UTC, bearophile wrote: Chris: I need an array that contains pointers to types created via template. To stick to my usual example: Person!(string) How can I make an array with pointers to concrete "instances" of Person!(string)? Every template creates a

Re: Pointer to template types?

2014-04-28 Thread Chris via Digitalmars-d-learn
On Monday, 28 April 2014 at 10:32:18 UTC, bearophile wrote: Chris: I need an array that contains pointers to types created via template. To stick to my usual example: Person!(string) How can I make an array with pointers to concrete "instances" of Person!(string)? Every template creates a

Re: Pointer to template types?

2014-04-28 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 28 April 2014 at 10:40:49 UTC, Chris wrote: So there is no way of filling an array with something like Person!(string) *pptr; foreach(person; people) { buf ~= &person; } Person!(string)*[] arr; Like this?

Re: Pointer to template types?

2014-04-28 Thread Chris via Digitalmars-d-learn
On Monday, 28 April 2014 at 10:44:18 UTC, Rene Zwanenburg wrote: On Monday, 28 April 2014 at 10:40:49 UTC, Chris wrote: So there is no way of filling an array with something like Person!(string) *pptr; foreach(person; people) { buf ~= &person; } Person!(string)*[] arr; Like this? Exactl

Re: Pointer to template types?

2014-04-28 Thread bearophile via Digitalmars-d-learn
Chris: So there is no way of filling an array with something like Person!(string) *pptr; foreach(person; people) { buf ~= &person; } So you want an array filled with instances of the same instantiation, sorry, I misunderstood your problem for a more complex one :-) Bye, bearophile

Re: Pointer to template types?

2014-04-28 Thread Chris via Digitalmars-d-learn
On Monday, 28 April 2014 at 11:04:17 UTC, bearophile wrote: Chris: So there is no way of filling an array with something like Person!(string) *pptr; foreach(person; people) { buf ~= &person; } So you want an array filled with instances of the same instantiation, sorry, I misunderstood yo

Re: Is this a bug?

2014-04-28 Thread Andrey via Digitalmars-d-learn
bearophile, John, probably, my example was not clear... The code below works. alias short Type1; alias Type1[100]* Type2; // if I take out '*' I will have to type it everywhere, because arrays in D2 always 'by value' struct Type3 { Type1 key; int flags; int arrLen;

Re: Is this a bug?

2014-04-28 Thread bearophile via Digitalmars-d-learn
Andrey: alias short Type1; The "alias X Y;" syntax is going to be deprecated, so use "alias Y = X;" if your compiler already supports it. alias Type1[100]* Type2; // if I take out '*' I will have to type it everywhere, because arrays in D2 always 'by value' Adding the * everywhere could

How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread ParticlePeter via Digitalmars-d-learn
DMD tells me "Error: variable m cannot be read at compile time", but why ? [code] struct MyStruct { float float_value = 0.0f ; ubyte ubyte_value = 2 ; } enum members = [ __traits( allMembers , MyStruct ) ] ; foreach( m ; members ) { mixin( "writeln( " ~ m ~ " , \" : \" , ( My

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread Andrej Mitrovic via Digitalmars-d-learn
On Monday, 28 April 2014 at 13:52:52 UTC, ParticlePeter wrote: DMD tells me "Error: variable m cannot be read at compile time", but why ? Because 'static foreach' is not an explicit feature yet, so it depends on the context. When you wrap the trait via: [__traits(allMembers, MyStruct)] You'

Re: Is this a bug?

2014-04-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 28 Apr 2014 06:04:53 -0400, John Colvin wrote: On Monday, 28 April 2014 at 09:36:08 UTC, Andrey wrote: not a bug. b.f[10] is indexing the pointer to the array, not the array itself. b.f[0][10] is indexing the array (with the 10), but I would argue it is better to write *(b.f)[10]

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread ParticlePeter via Digitalmars-d-learn
On Monday, 28 April 2014 at 13:57:56 UTC, Andrej Mitrovic wrote: On Monday, 28 April 2014 at 13:52:52 UTC, ParticlePeter wrote: DMD tells me "Error: variable m cannot be read at compile time", but why ? Because 'static foreach' is not an explicit feature yet, so it depends on the context. Whe

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread Andrej Mitrovic via Digitalmars-d-learn
On 4/28/14, ParticlePeter via Digitalmars-d-learn wrote: > I found the code with parenthesis in the dlang __traits docs and > also Philippe Sigauds "D Templates", and I haven't seen any other > example which works without them. So, when to use which syntax ( > for which purpose ) ? If you need to

Re: import with renaming and public import inside module

2014-04-28 Thread anonymous via Digitalmars-d-learn
On Monday, 28 April 2014 at 00:52:50 UTC, ketmar wrote: module my.module; public import other.module; … module mainprogram; import my.module; now i can access other.module symbols without qualifiers and another case: module mainprogram; import zmod = my.module; now i CAN'T access other.modul

Re: Is this a bug?

2014-04-28 Thread John Colvin via Digitalmars-d-learn
On Monday, 28 April 2014 at 14:02:33 UTC, Steven Schveighoffer wrote: On Mon, 28 Apr 2014 06:04:53 -0400, John Colvin wrote: On Monday, 28 April 2014 at 09:36:08 UTC, Andrey wrote: not a bug. b.f[10] is indexing the pointer to the array, not the array itself. b.f[0][10] is indexing the a

Re: 'auto' with AA

2014-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 04/28/2014 12:12 AM, David Held wrote: > Here is a compilable example which fails: > > void main() > { > double[int][string] nestedAA; > nestedAA["test"] = null; I think I see what's going on. The line above has almost no effect. For example, it does not populate "test" with an em

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread Philippe Sigaud via Digitalmars-d-learn
On Mon, Apr 28, 2014 at 5:45 PM, Andrej Mitrovic via Digitalmars-d-learn wrote: > If you need to store the tuple as an array to some variable, then you > would use that syntax. It all depends on what you're trying to do from > the call site. Ultimately it won't matter much once we finally get a >

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread Dicebot via Digitalmars-d-learn
On Monday, 28 April 2014 at 17:40:54 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: On Mon, Apr 28, 2014 at 5:45 PM, Andrej Mitrovic via Digitalmars-d-learn wrote: If you need to store the tuple as an array to some variable, then you would use that syntax. It all depends on what you're tr

Re: How to use the result of __traits( allMembers , T ) with string mixins ?

2014-04-28 Thread Philippe Sigaud via Digitalmars-d-learn
On Mon, Apr 28, 2014 at 8:20 PM, Dicebot via Digitalmars-d-learn wrote: > You can do the same iterating directly over allMembers list, why would you > prefer array here? Hmm, indeed. One advantage would be to get a range, and thus the power and filtering, mapping and co.

logging

2014-04-28 Thread xtimoner via Digitalmars-d-learn
synchronized class EventLog{ void opCall(string s){ std.file.append("logfile.txt", s); } } shared EventLog eventLog; Pleas, is it multithread safe and prefered way?

Re: logging

2014-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 04/28/2014 01:16 PM, xtimoner wrote: > synchronized class EventLog{ > void opCall(string s){ > std.file.append("logfile.txt", s); > } > } > > shared EventLog eventLog; > > Pleas, is it multithread safe and prefered way? Only if there is only one EventLog object. A synchroni

Re: Pointer to template types?

2014-04-28 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 28 April 2014 at 10:40:49 UTC, Chris wrote: Person!(string) *pptr; Just wanted to point out, the above is C style and not recommended. Person!(string)* pptr, pptr2, pptr3; In D the pointer is part of the type not the variable (all three are pointers, unlike C where only the

Re: Is this a bug?

2014-04-28 Thread Andrey via Digitalmars-d-learn
Ok, thanks a lot.. About dynamic arrays: I haven't found any information about internal representation of the D structures. E.g. do dynamic arrays have reference counter? Nevermind, I'm gonna use Type2[0] syntax.