Take a look at std::inner_product .

I would think a cleaner option is to implement them like std::inner_product only.

Let's not pollute std::vector.


On Tue, May 10, 2022 at 2:13 PM Patrik Tegelberg via Std-Proposals <std-proposals@lists.isocpp.org> wrote:

I often use vector math and usually make a small vector class overloading the math operators. I always lack a good option for element wise multiplication (Hadamard product). Divide becomes element wise divide, multiplication becomes the dot product and % becomes the cross product. There are no more operators with the correct precedence to overload. I suggest making another symbol, with multiplication precedence, available for overloading.

 

Matlab uses .* for their elementwise operations. They also use ./ and .^ so it is an established convention. But both dot and asterisk have other meanings in C++, maybe ¤ would be pretty, if we are allowed to use it.

The symbol is not that important, the important thing is to get another operator with multiplication precedence.

 

Best regards

Patrik Tegelberg

 

Sent from Mail for Windows

 

--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals


--
Mohit Saini