[REQUEST] float * Point<float> overload

Point<T> defines * for (Point<T>, T) but not the other way round. So myScalar*myVector will fail to compile.

Could we have bidirectional? So that one could transfer something like:

x = α u + β v

... directly to code?


why can't you just subclass Point and add your own overloaded operators? 

I don't really mind using {vector}{OPERATOR}{scalar}.

Just.. I would expect someone to expect the other way round.

I've been posting minutiae (e.g. where I expect A but the framework gives B) on-the-fly in case some of the feedback might be of some use.


Yeah, this is a good request, and something I'd been meaning to do. Will add it when I get a moment!

This is actually a pain in the donkey.

A naive approach...

template <typename T, U> Point<T> operator* (U multiplier, Point<T>point) noexcept { ...

... fails as {Rect}*{Point} snaffles the overload.

 Trying to get cunning with SFINAE http://coliru.stacked-crooked.com/a/1e226e96fc435f2a fails on Windows due to MSVC being a persistent pile of shit (https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/).

The least awkward method I can see is to temporarily promote the scalar to a double:

template <typename ValueType>
class Point
    static friend Point  operator* (double multiplier, Point<ValueType>point) noexcept {
        return Point((ValueType)(point.x * multiplier), (ValueType)(point.y * multiplier)); 


template <typename T>
Point<T> operator* (double multiplier, Point<T>point) noexcept {
    return Point<T>((T)(point.x * multiplier), (T)(point.y * multiplier));

I suppose I would prefer the former, as it keeps the overload within Point's declaration.


PS I would also consider macros to avoid duplicating otherwise identical code for each operator.

I already pushed something this morning.