220 31062 <CAOfiQqm1uLt-mm9-P0z0hEwi=6=jUoe-DTFf6VMyjjSpCW5OGg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: new operators (dot, cross, wedge, exponent)
Date: Wed, 22 Feb 2017 13:11:44 -0800
Lines: 134
Approved: news@gmane.org
Message-ID: <CAOfiQqm1uLt-mm9-P0z0hEwi=6=jUoe-DTFf6VMyjjSpCW5OGg@mail.gmail.com>
References: <53de9adb-1e05-46fc-8ac9-75fb331720fa@isocpp.org> <9bec1bf1-7fa6-faa4-4372-789b91387ce6@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a113c97fecbb3bd054924f2e4
X-Trace: blaine.gmane.org 1487797924 3215 195.159.176.226 (22 Feb 2017 21:12:04 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 22 Feb 2017 21:12:04 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDVNBJG4YAIBBJP5W7CQKGQEJ5GOAAQ@isocpp.org Wed Feb 22 22:12:00 2017
Return-path: <std-proposals+bncBDVNBJG4YAIBBJP5W7CQKGQEJ5GOAAQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f200.google.com ([209.85.128.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBBJP5W7CQKGQEJ5GOAAQ@isocpp.org>)
	id 1cgeCe-0000Q8-22
	for gclcip-std-proposals@m.gmane.org; Wed, 22 Feb 2017 22:12:00 +0100
Original-Received: by mail-wr0-f200.google.com with SMTP id q39sf5906687wrb.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 22 Feb 2017 13:12:06 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=5Lk62id4t9Dm5vviK70YJosVIMHONG4Nz+KtzeSnZJk=;
        b=PcSyxSInMQhnSLb+kKWqpnm24HNVbuzLwWLNpcNEdzSh9AGLtHrVmU/jxIJT8vA+Hy
         ghd+A0oYssjBloAgYWjqCx/ARa8R/zLmqj46rSGfF7DpfjZO2DnwDhjj2FT56TZxMs/X
         gF6mt2o71wky8jNqWsjvZasxIlLWC5V3OqJ3RfwHZoQg0IxmfsLkAiPsAt0lHB94+UDE
         qaxIIOS8F0C16AgikdZlZmQB19XeIH5h8KHktl1mX6AdHtRJhQDFoaDsT2hmNqlIqeJP
         6DlpwX2si3GijwiBhX+31yyG0QnMdAFLJiiw8HVLp8I/QCQOou/CARyaS2ZmECG+4cyK
         LPhw==
X-Gm-Message-State: AMke39klyTItsWonuZw7Eqx2LB0EQns7IUPtdF1eK0ucZrC/138ZwvPovQmWYCYD1sM6EQ==
X-Received: by 10.223.171.81 with SMTP id r17mr1369597wrc.12.1487797926045;
        Wed, 22 Feb 2017 13:12:06 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.10.66 with SMTP id 63ls396747wmk.0.gmail; Wed, 22 Feb 2017
 13:12:05 -0800 (PST)
X-Received: by 10.223.136.79 with SMTP id e15mr14747952wre.14.1487797925063;
        Wed, 22 Feb 2017 13:12:05 -0800 (PST)
Original-Received: from mail-wr0-x22c.google.com (mail-wr0-x22c.google.com. [2a00:1450:400c:c0c::22c])
        by mx.google.com with ESMTPS id w4si4068679wme.115.2017.02.22.13.12.05
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 22 Feb 2017 13:12:05 -0800 (PST)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2a00:1450:400c:c0c::22c as permitted sender) client-ip=2a00:1450:400c:c0c::22c;
Original-Received: by mail-wr0-x22c.google.com with SMTP id s27so10629473wrb.2
        for <std-proposals@isocpp.org>; Wed, 22 Feb 2017 13:12:05 -0800 (PST)
X-Received: by 10.223.176.70 with SMTP id g6mr25138970wra.12.1487797924631;
 Wed, 22 Feb 2017 13:12:04 -0800 (PST)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.80.172.225 with HTTP; Wed, 22 Feb 2017 13:11:44 -0800 (PST)
In-Reply-To: <9bec1bf1-7fa6-faa4-4372-789b91387ce6@gmail.com>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of metafoo@gmail.com
 designates 2a00:1450:400c:c0c::22c as permitted sender) smtp.mailfrom=metafoo@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:31062
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31062>

--001a113c97fecbb3bd054924f2e4
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 22 February 2017 at 11:54, Jonathan M=C3=BCller <jonathanmueller.dev@gma=
il.com
> wrote:

> Instead of specifically adding those specific operators, I rather like a
> more general solution - that has probably been discussed before: infix
> calling notation for functions.
>
> As an extended uniform call syntax allow a binary function call `f(a, b)`
> to be written as `a f b`.
> I don't know whether this would work like so, but maybe `a `f` b` or
> something like that?
>
> This would allow the `a cross b` and `a dot b` you wanted.


I forget who originally came up with this, but something along these lines
is already possible:


template<typename T> struct identity { typedef T type; };
template<typename T> using identity_t =3D typename identity<T>::type;

template<typename A, typename B, typename C> struct OperatorLhs {
  B b;
  A (*fn)(B, C);
  friend A operator*(OperatorLhs &&lhs, C c) { return
lhs.fn(static_cast<B>(lhs.b), static_cast<C>(c)); }
};
template<typename A, typename B, typename C>
OperatorLhs<A, B, C> operator*(identity_t<B> b, A (*fn)(B, C)) {
  return {static_cast<B>(b), fn};
}


struct Vec {};
Vec cross(const Vec &, const Vec &);

Vec a, b;
Vec x =3D a *cross* b;


(where the choice of the "surrounding" operator dictates the precedence of
the resulting pseudo-operator). This does not support the operator in
question being overloaded (or a template), but you can fix that and package
this up into the following form:


struct Cross : InfixFunction<Cross, std::multiplies> {
  Vec operator()(const Vec &, const Vec&) const;
  // ... more operator() overloads if you want ...
};
inline constexpr Cross cross;

Vec a, b;
Vec x =3D cross(a, b);
Vec y =3D a *cross* b;

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAOfiQqm1uLt-mm9-P0z0hEwi%3D6%3DjUoe-DTFf6VMyjjS=
pCW5OGg%40mail.gmail.com.

--001a113c97fecbb3bd054924f2e4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 2=
2 February 2017 at 11:54, Jonathan M=C3=BCller <span dir=3D"ltr">&lt;<a hre=
f=3D"mailto:jonathanmueller.dev@gmail.com" target=3D"_blank">jonathanmuelle=
r.dev@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex">Instead of specifically adding those specific operators, I =
rather like a more general solution - that has probably been discussed befo=
re: infix calling notation for functions.<br>
<br>
As an extended uniform call syntax allow a binary function call `f(a, b)` t=
o be written as `a f b`.<br>
I don&#39;t know whether this would work like so, but maybe `a `f` b` or so=
mething like that?<br>
<br>
This would allow the `a cross b` and `a dot b` you wanted.</blockquote><div=
><br></div><div>I forget who originally came up with this, but something al=
ong these lines is already possible:</div><div><br></div><div><br></div><di=
v>template&lt;typename T&gt; struct identity { typedef T type; };</div><div=
>template&lt;typename T&gt; using identity_t =3D typename identity&lt;T&gt;=
::type;</div><div><br></div><div>template&lt;typename A, typename B, typena=
me C&gt; struct OperatorLhs {</div><div>=C2=A0 B b;</div><div>=C2=A0 A (*fn=
)(B, C);</div><div>=C2=A0 friend A operator*(OperatorLhs &amp;&amp;lhs, C c=
) { return lhs.fn(static_cast&lt;B&gt;(lhs.b), static_cast&lt;C&gt;(c)); }<=
/div><div>};</div><div>template&lt;typename A, typename B, typename C&gt;</=
div><div>OperatorLhs&lt;A, B, C&gt; operator*(identity_t&lt;B&gt; b, A (*fn=
)(B, C)) {</div><div>=C2=A0 return {static_cast&lt;B&gt;(b), fn};</div><div=
>}</div><div><br></div><div><br></div><div>struct Vec {};</div><div>Vec cro=
ss(const Vec &amp;, const Vec &amp;);</div><div><br></div><div>Vec a, b;</d=
iv><div>Vec x =3D a *cross* b;<br></div><div><br></div><div><br></div><div>=
(where the choice of the &quot;surrounding&quot; operator dictates the prec=
edence of the resulting pseudo-operator). This does not support the operato=
r in question being overloaded (or a template), but you can fix that and pa=
ckage this up into the following form:</div><div><br></div><div><br></div><=
div>struct Cross : InfixFunction&lt;Cross, std::multiplies&gt; {</div><div>=
=C2=A0 Vec operator()(const Vec &amp;, const Vec&amp;) const;</div><div>=C2=
=A0 // ... more operator() overloads if you want ...</div><div>};</div><div=
>inline constexpr Cross cross;</div><div><br></div><div>Vec a, b;</div><div=
>Vec x =3D cross(a, b);<br></div><div><div>Vec y =3D a *cross* b;</div></di=
v></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm1uLt-mm9-P0z0hEwi%3D6%3DjUoe-=
DTFf6VMyjjSpCW5OGg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm1uLt-=
mm9-P0z0hEwi%3D6%3DjUoe-DTFf6VMyjjSpCW5OGg%40mail.gmail.com</a>.<br />

--001a113c97fecbb3bd054924f2e4--

.
