Thread overview | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 23, 2012 [Issue 9066] New: Implement constructor forwarding template | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9066 Summary: Implement constructor forwarding template Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-23 11:02:26 PST --- This would alleviate the need to write boilerplate code by hand, e.g.: class MyException : Exception { mixin ForwardCtors; } An experimental implementation is provided in the attachment. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 23, 2012 [Issue 9066] Implement constructor forwarding template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-23 11:02:46 PST --- Created an attachment (id=1165) code -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 31, 2012 [Issue 9066] Implement constructor forwarding template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> 2012-12-31 09:57:25 PST --- *** Issue 8965 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 04, 2013 [Issue 9066] Implement constructor forwarding template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-04 12:00:13 PST --- There's a few problems: Default values aren't handled, and they could be initialized with a non-accessible private value. The parameter types could also be private types which might not be accessible. It would definitely be simpler to implement inheriting constructors, C++11 has them, described here: http://stackoverflow.com/questions/9979194/what-is-constructor-inheritance Perhaps we could implement something similar via: class C : B { alias super.this this; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 03, 2013 [Issue 9066] Implicit constructor inheritance | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 Martin Nowak <code@dawg.eu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |code@dawg.eu Summary|Implement constructor |Implicit constructor |forwarding template |inheritance --- Comment #4 from Martin Nowak <code@dawg.eu> 2013-10-03 15:56:49 PDT --- I think what we want is implicit constructor inheritance even for non-default constructors. The same rules should apply. > Default values aren't handled, and they could be initialized with a non-accessible private value. Depends on the scope of default values, I'm not sure about this right now. If they live in the callee scope it'll work fine. If they live in the caller scope your constructor isn't callable from outside of the module and your constructor should be private. > The parameter types could also be private types which might not be accessible. Same here your constructor should be private. Old forum post on the topic of constructor inheritance. http://forum.dlang.org/thread/fqk4jb$n76$1@digitalmars.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 04, 2013 [Issue 9066] Implicit constructor inheritance | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-04 04:09:58 PDT --- Copying my comment from github: C++11 has this feature: http://stackoverflow.com/questions/9979194/what-is-constructor-inheritance I think the only real issue is what syntax to use in D. C++ uses: ----- using Base::Base; ----- At first glance in D it would be: ----- alias Base.this this; // or Super.this ----- But this conflicts with the subtyping syntax. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 04, 2013 [Issue 9066] Add constructor inheritance feature | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #6 from Martin Nowak <code@dawg.eu> 2013-10-04 11:27:29 PDT --- (In reply to comment #5) Inheriting the default constructor is implicit so why would you need an explicit syntax for non-default constructors? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 04, 2013 [Issue 9066] Add constructor inheritance feature | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-04 11:37:43 PDT --- (In reply to comment #6) > (In reply to comment #5) > > Inheriting the default constructor is implicit so why would you need an explicit syntax for non-default constructors? The last time this was discussed (IIRC), people were against this. Maybe my memory is bad. We could have another go at a newsgroup discussion. I haven't yet looked at the C++11 spec, but I wonder why they too haven't made constructor inheritance implicit. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 04, 2013 [Issue 9066] Add constructor inheritance feature | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-04 12:01:23 PDT --- (In reply to comment #6) > (In reply to comment #5) > > Inheriting the default constructor is implicit so why would you need an explicit syntax for non-default constructors? I guess the real issue is that you could easily end up instantiating an object which hasn't been properly initialized (properly meaning how the class designer defines it). For example: ----- class A { this(float x) { this.x = x; } float x; } class B : A { this(float x, float y) { super(x); this.y = y; } float y; } void main() { auto b = new B(1.0); // B's ctor not called } ----- Nevermind that we have .init, a class designer probably wants to have explicit control of which constructors can be called by the user. If all base class ctors are inherited.. well you saw the example. Another interesting example: ----- class A { this(float x) { this.x = x; } float x; } class B : A { this(float x, float y) { super(x); this.y = y; } const(float) y; } void main() { // this should not compile since y must be initialized // in the class B ctor, which wasn't called. auto b = new B(1.0); } ----- So the user could easily get a half-constructed object, or bad diagnostics about some const field not being initialized. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 05, 2013 [Issue 9066] Add constructor inheritance feature | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=9066 --- Comment #9 from Martin Nowak <code@dawg.eu> 2013-10-05 09:01:17 PDT --- (In reply to comment #8) Your example wouldn't compile. You can't default construct a class that defines a non-default constructor even though we do have implicit constructor inheritance. The rule here is very simple, if you define a constructor none is inherited. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation