C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Add operator for element wise multiplication.

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Mon, 16 May 2022 11:44:25 +0100
You know you can spell it as
   x *hadamard* y
by defining
static constexpr hadamard_t final {
    struct hadamard_proxy_t {
        matrix const* m;
        friend auto operator*(hadamard_proxy_t const& self, matrix const&
y) -> matrix {
            return hadamard_product(*self.m, y);
        }
    };
    friend auto operator*(matrix const& x, hadamard_t) -> hadamard_proxy_t {
        return hadamard_proxy_t{&x};
    }
};

I omitted the associativity helpers which are symmetric for brevity, and of
course I completely neglected all the lvalue/rvalue forwarders, but it's
close enough to give a hint.

G

On Mon, May 16, 2022 at 9:58 AM Patrik Tegelberg via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> P.S. about overloading operator ->*.
>
> Come to think of it, the dot product can not use *= so I’ll let * mean
> point wise, which do use **= and let ->** mean dot product, so ->*= is
> never needed.
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows
>
>
>
> *From: *Sebastian Wittmeier via Std-Proposals
> <std-proposals_at_[hidden]>
> *Sent: *Sunday, 15 May 2022 22:08
> *To: *std-proposals_at_[hidden]
> *Cc: *Sebastian Wittmeier <wittmeier_at_[hidden]>
> *Subject: *Re: [std-proposals] Add operator for element wise
> multiplication.
>
>
>
> Hi Patrik,
>
> operator->* (pointer-to-member) can be overridden and is very similar in
> precedence to multiplication (one step higher only).
>
> Best,
>
> Sebastian
>
> --
>
> Sebastian Wittmeier
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-05-16 10:44:37