Tsoding streamed about D

Meta jared771 at gmail.com
Wed Mar 19 06:36:28 UTC 2025


On Wednesday, 19 March 2025 at 06:05:24 UTC, Manu wrote:
> On Wed, 19 Mar 2025 at 11:36, Meta via Digitalmars-d < 
> digitalmars-d at puremagic.com> wrote:
>>
>> "This language is garbage collected, and they're _fucking 
>> ashamed_ of that!"
>>
>> This guy is surprisingly perceptive and 100% accurate with his 
>> cutting observations hahaha.
>>
>
> Why didn't his operator overloading experiment work?
>
> struct S {
>     int x;
> }
>
> // non-member opBinary
> S opBinary(string s : "+")(S lh, S rh) {
>     return S(lh.x + rh.x);
> }
>
> void main()
> {
>     S a, b;
>     S s1 = a.opBinary!"+"(b); // <- UFCS works, as expected
>     S s2 = a + b; // ERROR: doesn't work! why not? the rewrite 
> should work
> via UFCS as above...
> }

I don't know the specific compiler details, but you make a good 
point that this _should_ work via UFCS. Probably the compiler 
first checks that it's a member function or something.

> I can't imagine any good reason his experiment should have 
> failed. I would want this too when extern to a C lib; it hasn't 
> come up for me before, but if it did, I would log a bug 
> instantly.

Yeah, I've always wanted free-standing operator overload 
functions in D, and I think the case for them has only gotten 
stronger with better C and C++ integration, and _especially_ with 
ImportC.

His other main gripe was that the compiler rejects .h files, even 
though when he changed the extension to .c, it compiled and ran 
just fine. In the footnote section he actually downloads the 
source code and modifies it to compile .h files, and it's a 
surprisingly simple change. I wonder if there's a specific reason 
Walter didn't allow it.


More information about the Digitalmars-d mailing list