www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: [opAssign] why no overload/forbidding for '='

reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <c9qiqn$1i01$1 digitaldaemon.com>, Walter says...

The trouble with allowing structs to have constructors, is <snip>

If everyone would be satisfied with 1) no destructors and 2) bit copies for
assignment and copy constructor and 3) no RAII for structs, I would be much
more amenable to adding them in <g>.

So, two months have gone by since the above quote, and pretty much everyone has said they could live with 1), 2) and 3). And now we have constructors for primitives. You see where this is leading...? The thing that we really need for generic programming, though, is consistency. As near as possible - the same syntax for all types. Consider the follwing possible D statements: (1) T x = new T(); (2) T* x = new T(); (3) T x = T(); (1) is appropriate for classes only; (2) is appropriate for primitives allocated on the heap only; (3) is appropriate for either structs or classes which happen to have overridden static opCall(). This is very counterintuitive. So, how hard would it be to make something like: # T x(); construct all types, as it does in C++? (Oh, and to have # int x(5); initialize x to 5, not 0, as it does in C++)? I'm not too bothered about the exact syntax (althernatives have been suggested by others), only that the syntax be the same for everything. Oh, and primitives and structs should still end up on the stack, not the heap - it's not /allocating/ them that's desirable, it's /initializing/ them (with consistent syntax). Arcane Jill
Aug 07 2004
parent Christopher Stevenson <Christopher_member pathlink.com> writes:
The thing that we really need for generic programming, though, is consistency.
As near as possible - the same syntax for all types. Consider the follwing
possible D statements:

(1)    T x = new T();
(2)    T* x = new T();
(3)    T x = T();

Now, I'm up THAT up to speed to classes and templates and all the various uses, but why can classes be treated like other (built-in) types, and objects be built automatically upon entering scope, in the order as declared: class C { this(); } int myFunc() { C c; .. return 0; } and for constructors: class C { this(int a) { } } int myFunc(); { int val = 15; C c = C(val); .. return 0; } You can distinguish between a constructor call and static opCall by whether or not it's part of a declaration statement. I still feel like I'm missing something, though... --Christopher Stevenson Deployed for OIF2 since 2 Mar 04. (Almost 1/2 way done!)
Aug 07 2004