DUAL FEATURE REQUEST: let "with" take a struct pointer and evaluate to its parameter

Jarrod qwerty at ytre.wq
Sat Dec 22 05:02:23 PST 2007


On Thu, 20 Dec 2007 12:11:04 -0500, Jarrett Billingsley wrote:

> I like the idea, but I don't know why we can't just have (1) proper
> struct literals for non-static struct instances and (2) initialization
> of heap-allocated structs at allocation time.
> 
> // stack-allocated struct
> auto s = MyStruct { bar: 23, baz: 42 };
> 
> // heap-allocated struct
> auto s2 = new MyStruct { bar: 23, baz: 42 };
> 
> Or, hell, constructors and named params. Instead, we have inconsistency
> and ugliness:
> 
> struct MyStruct
> {
>     int baz, bar;
> }
> 
> // Look at that pretty struct initializer! static MyStruct s = { bar:
> 23, baz: 42 };
> 
> // Is it a function?  Is it a call to opCall?  Why // can't I name the
> members or initialize them out of // order or leave some uninitialized? 
> Why is this // so different from the static case? auto s2 = MyStruct(42,
> 23);
> 
> // NOW what?!  Now I have an instance on the heap that's // filled with
> default values.. how do I initialize it? // I have to separate out the
> initialization into some // method function and call it as a separate
> step. auto s = new MyStruct;
> 
> // And again I can't name anything.
> s.initialize(42, 23);
> 
> Dumb, dumb, dumb.  Don't even get me started on the "blessing" of static
> opCall.  Are we *trying* to make stupid special cases?

I completely agree with this. Consistency really needs to be found.
Perhaps named parameters should be optional for ease, but aside from that 
I would really like to see this idea implemented.



More information about the Digitalmars-d mailing list