[Issue 9112] New: Uniform default construction
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 3 20:06:11 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9112
Summary: Uniform default construction
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-12-03 20:06:08 PST ---
Related: http://d.puremagic.com/issues/show_bug.cgi?id=8752
Built-in .init property is useful, but it is sometimes unsafe, and many people
might confuse the default initializer and construction.
- Default initializer represents pre-constructing object state.
Users can access to it by using built-in `.init` property.
- Default construction is a default operation which constructing an object
completely.
* For built-in types (int, double, pointers, arrays) and class types,
default construction does nothing. Because, after initializing by
default initializer, the object is already completely constructed.
* For struct types, it is same in basic. After initialized by S.init,
the object is completely constructed. Except:
+ If S is a nested struct, default construction should fill
its frame pointer. So default construction is valid only in
the function where S is defined.
+ If S is a struct which has `@disable this();`, default construction
is disabled explicitly. So default construction is never occur.
Instead, users should call explicitly defined user-defined
constructor which has arguments.
Well, for struct types, default construction has an explicit syntax S().
But, built-in types does not have that. It is inconsistent.
So I'd like to propose new syntax to reduce such concept confusion.
int n = int(); // same as int.init
int n = int(10); // same as cast(int)10;
>From the meta-programming view, we can represent default construction of value
types by T().
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list