digitalmars.D.bugs - [Issue 4086] New: Standard struct constructor for the heap
- d-bugmail puremagic.com (51/51) Apr 12 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4086
- d-bugmail puremagic.com (10/10) Jan 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=4086
http://d.puremagic.com/issues/show_bug.cgi?id=4086
Summary: Standard struct constructor for the heap
Product: D
Version: future
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
D allows to initialize a struct on the stack with a default syntax:
struct Node {
int data;
Node* next;
}
void main() {
Node n1 = Node(10); // OK
Node n2 = Node(10, null); // OK
}
So I propose to introduce that same handy automatic syntax for heap allocation
too:
struct Node {
int data;
Node* next;
}
void main() {
Node* n1 = new Node(10); // OK
Node* n2 = new Node(10, null); // OK
}
This feature doesn't increase the complexity of the language for the
programmer, it lowers the complexity because there is one less special case to
remember (even if the compiler can become a bit more complex).
To keep things tidy, such default costructor must be absent if any other
costructor is defined in the struct:
struct Foo {
int data;
Foo* next;
this(int d, Foo* p) {
data = d;
next = p;
}
}
void main() {
Foo* f = new Foo(10); // Error, standard constructor is absent
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4086
Andrei Alexandrescu <andrei metalanguage.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |andrei metalanguage.com
AssignedTo|nobody puremagic.com |andrei metalanguage.com
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011








d-bugmail puremagic.com