<br><br><div class="gmail_quote">On Sun, Mar 14, 2010 at 14:14, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have tried to use the new operators of D2 and I have found several problems. This small program shows two of those problems (some of my problems can be caused by my improper usage, I'm trying to tell apart the operator overloading bugs from my improper usage cases).<br>
void main() {<br>
Foo f = Foo(5);<br>
f++; // line 16<br>
auto a = new int[f]; // line 17<br>
}<br>
<br>
Errors:<br>
temp2.d(16): Error: var has no effect in expression (__tmp1)<br></blockquote><div><br>Try ++f, it works. I guess ++f is rewritten f.opUnary!"++"(), but f++ must have create a temporary variable.<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
temp2.d(17): Error: cannot implicitly convert expression (f) of type Foo to uint<br>
<br>
Note: the line 17 works if I write it this way, but it's not nice:<br>
auto a = new int[cast(uint)f];<br>
<br></blockquote><div><br>Note the error message: cannot *implicitly* convert expresion (f).<br>opCast defines the explicit cast operation, it has no effect on implicit casting. Having an opImplicitCast(T) would be nice, I agree.<br>
<br>For now, this also does not work:<br><br>void bar(int i) {}<br><br>(in main:)<br> bar(f); // Error: cannot implicitly convert expresion (f) of type Foo to int.<br><br>That's sad, I'd like to have std.variant.Variant defining an opCast. That way, you could do:<br>
<br>void foo(int i) {}<br>void bar(string s) {}<br><br>Variant v;<br>v = 3;<br>foo(v); // try to cast v to int implicitly: works, move along.<br>v = "abc";<br>bar(v); // implicit cast to string, works.<br>
<br><br> Philippe<br><br></div></div>