digitalmars.D - Is there something like anonymous struct?
- eGust (26/26) Mar 04 2013 I need something to store some functions, and it only will be
- anonymous (3/14) Mar 04 2013 import std.typecons: tuple;
- Steven Schveighoffer (9/26) Mar 04 2013 That doesn't name them. I think you have to be more verbose when naming...
- Jacob Carlborg (5/11) Mar 04 2013 This is a proposal I had before:
- eGust (3/20) Mar 04 2013 Yes, it looks better. Can tuple guarantee the order and alignment
- Steven Schveighoffer (5/26) Mar 05 2013 It will be equivalent to a struct declared with those members.
- eGust (13/42) Mar 05 2013 Thank you all guys. I'll use tuple. This way will make it faster
I need something to store some functions, and it only will be used once. There is my code now: struct Funcs { auto func1 = &fn1, func2 = &fn2, ... funcN = &fnN; } __gshared immutable Funcs foo; export extern(Windows) auto bar() { return &foo; } ============ Can I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }
Mar 04 2013
On Tuesday, 5 March 2013 at 02:01:47 UTC, eGust wrote:Can I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }import std.typecons: tuple; __gshared immutable foo = tuple(&fn1, &fn2, ...);
Mar 04 2013
On Mon, 04 Mar 2013 21:15:27 -0500, anonymous <anonymous example.com> wrote:On Tuesday, 5 March 2013 at 02:01:47 UTC, eGust wrote:That doesn't name them. I think you have to be more verbose when naming the members: __gshared immutable foo = Tuple!(typeof(&fn1), "func1", typeof(&fn2), "func2")(&fn1, &fn2); Wow, that really sucks. Is there a better way? I bet a mixin could help here... -SteveCan I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }import std.typecons: tuple; __gshared immutable foo = tuple(&fn1, &fn2, ...);
Mar 04 2013
On 2013-03-05 03:33, Steven Schveighoffer wrote:That doesn't name them. I think you have to be more verbose when naming the members: __gshared immutable foo = Tuple!(typeof(&fn1), "func1", typeof(&fn2), "func2")(&fn1, &fn2); Wow, that really sucks. Is there a better way? I bet a mixin could help here...This is a proposal I had before: http://forum.dlang.org/thread/kfbnuc$1cro$1 digitalmars.com -- /Jacob Carlborg
Mar 04 2013
On Tuesday, 5 March 2013 at 02:15:33 UTC, anonymous wrote:On Tuesday, 5 March 2013 at 02:01:47 UTC, eGust wrote:Yes, it looks better. Can tuple guarantee the order and alignment of the elements? I need an interface with other languages.Can I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }import std.typecons: tuple; __gshared immutable foo = tuple(&fn1, &fn2, ...);
Mar 04 2013
On Mon, 04 Mar 2013 21:58:57 -0500, eGust <egustc gmail.com> wrote:On Tuesday, 5 March 2013 at 02:15:33 UTC, anonymous wrote:It will be equivalent to a struct declared with those members. However, I would say if you are looking for a type to push across languages, why not declare the type? -SteveOn Tuesday, 5 March 2013 at 02:01:47 UTC, eGust wrote:Yes, it looks better. Can tuple guarantee the order and alignment of the elements? I need an interface with other languages.Can I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }import std.typecons: tuple; __gshared immutable foo = tuple(&fn1, &fn2, ...);
Mar 05 2013
On Tuesday, 5 March 2013 at 16:02:50 UTC, Steven Schveighoffer wrote:On Mon, 04 Mar 2013 21:58:57 -0500, eGust <egustc gmail.com> wrote:Thank you all guys. I'll use tuple. This way will make it faster and easier. If QtD can be built with 2.062, I would do all my work in D. Now I'm using CPP which is I'd never used before. It already bothers me. Now I'm writing C-style CPP for GUI and D for all the others in the same time, so I must try to reduce the number of the interface functions. That's why I don't wanna waste my time on repeating the same declarations, especially it's a trouble if I make any change. Because it's easy to output the type of var in D, I think I can make them declared in the end. :)On Tuesday, 5 March 2013 at 02:15:33 UTC, anonymous wrote:It will be equivalent to a struct declared with those members. However, I would say if you are looking for a type to push across languages, why not declare the type? -SteveOn Tuesday, 5 March 2013 at 02:01:47 UTC, eGust wrote:Yes, it looks better. Can tuple guarantee the order and alignment of the elements? I need an interface with other languages.Can I write something like this: __gshared immutable foo = { auto func1 = &fn1, func2 = &fn2, ... } Or just ... = { &fn1, &fn2, ... }import std.typecons: tuple; __gshared immutable foo = tuple(&fn1, &fn2, ...);
Mar 05 2013