Should we add `a * b` for vectors?
jmh530
john.michael.hall at gmail.com
Thu Sep 28 00:51:55 UTC 2017
On Wednesday, 27 September 2017 at 23:25:34 UTC, Manu wrote:
>
> Again, sadly, D has no ADL, and this will be an unmitigated
> disaster as a
> result!
> Instantiations of templates will use the default elementwise
> operator
> instead of the one you specified in your module, and nobody
> will understand
> why.
Argument-dependent lookup? I'm not an expert on C++, but I read
the wikipedia entry on it. It does seem like an issue worth
thinking more about
One (hacky) solution is to not have default implementations for
the all the operators (the focus so far has been on the multiple
uses of * for element-wise multiply and dot product/matrix
multiplication). So you have Slice in mir.ndslice.slice. Then
make a mir.ndslice.operator.elementwise module that has the
operator overloading for elementwise operations, then a module
mir.ndslice.operator.linalg (or somewhere in lubeck) with the dot
product or inverse implementations. The key to making this work
is that you also need a mid.ndslice.arithmetic or something that
allows the user to call these functions without operator
overloading. This way they can put import their default, but if
they have a function that mixes and matches dot and element-wise
multiplication, they can do that too.
More information about the Digitalmars-d
mailing list