digitalmars.D.learn - Trouble with destroy
- Namespace (22/22) Sep 23 2013 Code:
- Namespace (5/27) Sep 23 2013 As always. As soon as you wrote it, you've got the solution.
- Meta (5/9) Sep 23 2013 This still seems like it should be worth reporting. I can't
- Jonathan M Davis (10/20) Sep 23 2013 The problem is that the type matches two different templated functions, ...
- H. S. Teoh (6/16) Sep 23 2013 IIRC, D templates don't have best-match like C++ does; it was an
- Jonathan M Davis (6/20) Sep 23 2013 Correct. For IFTI to work, the arguments need to pass exactly one of the...
- Namespace (3/34) Oct 25 2013 Because this solution does not work anymore with dmd 2.064 beta:
Code: ---- import std.stdio; struct A { public: int[4] val; alias val this; } void main() { A a; a.destroy(); } ---- /d824/f630.d(13): Error: template object.destroy matches more than one template declaration, /opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T obj) if (is(T == struct)) and /opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], U, ulong n)(ref T obj) Nice. What should I do?
Sep 23 2013
On Monday, 23 September 2013 at 19:06:48 UTC, Namespace wrote:Code: ---- import std.stdio; struct A { public: int[4] val; alias val this; } void main() { A a; a.destroy(); } ---- /d824/f630.d(13): Error: template object.destroy matches more than one template declaration, /opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T obj) if (is(T == struct)) and /opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], U, ulong n)(ref T obj) Nice. What should I do?As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----
Sep 23 2013
On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
Sep 23 2013
On Tuesday, September 24, 2013 05:18:38 Meta wrote:On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:The problem is that the type matches two different templated functions, and as it stands, there is no way for the compiler to disambiguate. They're both equally valid. The only way that they could be disambiguated would be if the compiler preferred the actual type over the aliased one (which arguably, it should, but it clearly it doesn't at this point, and I don't know what all of the ramifications are if it did). But I don't think that there's anything wrong with destroy in this case. If there's a problem, it's with how alias this is handled when determining which overloaded template to use. - Jonathan M DavisAs always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
Sep 23 2013
On Tue, Sep 24, 2013 at 05:18:38AM +0200, Meta wrote:On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:IIRC, D templates don't have best-match like C++ does; it was an explicit design choice that multiple matching templates is an error. T -- Lawyer: (n.) An innocence-vending machine, the effectiveness of which depends on how much money is inserted.As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
Sep 23 2013
On Monday, September 23, 2013 22:45:33 H. S. Teoh wrote:On Tue, Sep 24, 2013 at 05:18:38AM +0200, Meta wrote:Correct. For IFTI to work, the arguments need to pass exactly one of the overloads' template constraints. If they pass the template constraints for multiple overloads, then it's an ambiguity error. There is no attempt to figure out which matches "better." - Jonathan M DavisOn Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:IIRC, D templates don't have best-match like C++ does; it was an explicit design choice that multiple matching templates is an error.As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
Sep 23 2013
On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:On Monday, 23 September 2013 at 19:06:48 UTC, Namespace wrote:Because this solution does not work anymore with dmd 2.064 beta: Are there any other tips and tricks?Code: ---- import std.stdio; struct A { public: int[4] val; alias val this; } void main() { A a; a.destroy(); } ---- /d824/f630.d(13): Error: template object.destroy matches more than one template declaration, /opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T obj) if (is(T == struct)) and /opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], U, ulong n)(ref T obj) Nice. What should I do?As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----
Oct 25 2013
On Friday, 25 October 2013 at 07:29:16 UTC, Namespace wrote:Because this solution does not work anymore with dmd 2.064 beta: Are there any other tips and tricks?File regression and write to dmd beta mail list. It is clearly lack of extra constraint on `T : U[n]` overload (it should explicitly check that T is not an aggregate)
Oct 25 2013
On Friday, 25 October 2013 at 11:10:03 UTC, Dicebot wrote:On Friday, 25 October 2013 at 07:29:16 UTC, Namespace wrote:http://forum.dlang.org/thread/bug-11344-3 http.d.puremagic.com%2Fissues%2FBecause this solution does not work anymore with dmd 2.064 beta: Are there any other tips and tricks?File regression and write to dmd beta mail list. It is clearly lack of extra constraint on `T : U[n]` overload (it should explicitly check that T is not an aggregate)
Oct 25 2013
On Friday, 25 October 2013 at 12:09:34 UTC, Namespace wrote:http://forum.dlang.org/thread/bug-11344-3 http.d.puremagic.com%2Fissues%2FK, I have sent a mail to beta list pointing to it. IMHO `destroy` constraints need to be much more strict as destroying only part of object via `alias this` unlikely ever to make sense and is very error-prone.
Oct 25 2013