operator overloading outside the type
ltdk
khoa.alter.acc at gmail.com
Sun Mar 30 06:56:50 UTC 2025
On Sunday, 30 March 2025 at 05:30:42 UTC, sfp wrote:
>
> I want to be able to define standard mathematical operators for
> standard mathematical entities (numbers, matrices, polynomials,
> etc). My code is nontrivial because of the domain I work in,
> not because of the code itself. By and large, D has helped make
> the code I've written significantly shorter, clearer, and more
> understandable than the equivalent C++ code I would have
> written. In the past I'd all but given up on doing any serious
> metaprogramming in C++ because of the abysmal compile times,
> and now I can actually do it. It's damn useful and has made my
> life easier. It's really a testament to how well designed the
> language is and how well the features come together.
>
> Not being able to define operators as free functions was a
> surprising restriction. I've done my best to understand the
> technical issues surrounding this feature, and my assessment is
> that there is no real impediment to enabling it other than
> generational trauma inherited from C++.
You may want to try Julia. It supports multiple dispatch,
operator overloading as free functions.
Look at how [operators on Sparse Arrays are
implemented](https://github.com/JuliaSparse/SparseArrays.jl/blob/9a4656134eece3483216ce1244bd0b3a20aee6f1/src/linalg.jl#L214). It's soo good.
More information about the Digitalmars-d
mailing list