Should we add `a * b` for vectors?

Dukc ajieskola at gmail.com
Wed Oct 4 09:28:13 UTC 2017


On Tuesday, 3 October 2017 at 19:25:32 UTC, Walter Bright wrote:
> This is specifically designed to prevent nasty surprises. C++ 
> has a big problem with ADL in that overloading is not 
> encapsulated and any #included header can inadvertently add 
> more overloads that may be entirely unrelated. Any .h can crack 
> open any namespace and insert more overloads into it. It's 
> completely unhygienic and uncontrollable.
>
> As for the specific example you gave, I get:
>
> a.d(3): Error: no property 'front' for type 'int[]'
> a.d(4): Error: no property 'save' for type 'int[]'
> b.d(8): Error: template instance a.sum!(int[]) error 
> instantiating

But you can't deny our solution eats expressive power: If you 
don't want to change code you're importing, you have to write a 
wrapper type for int[] here. Alias this helps, but because save() 
and slicing operators have to return the type of this, there's 
still manual work to do if you want Phobos algorithms to utilize 
it's random access.

It may be that ADL or something similar would cause too much 
trouble to be worth it, don't know about that. But what I'm 
saying that we definitely have a considerable problem here and it 
would solve it.


More information about the Digitalmars-d mailing list