220 18905 <CAD6_Qj-rVOiyfabWgs=5Kniv9W9zyTZHUDo-SrAtAOKk4AApGw@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Unified coercion protocol: static_cast explicit overload
Date: Wed, 1 Jul 2015 16:53:29 +0100
Lines: 214
Approved: news@gmane.org
Message-ID: <CAD6_Qj-rVOiyfabWgs=5Kniv9W9zyTZHUDo-SrAtAOKk4AApGw@mail.gmail.com>
References: <5c654bc3-5294-4f8a-bf1a-bf4a9f6c8603@isocpp.org>
	<CAKiZDp2p=a2c+vt6bo47vR=f=QU-UqPiuFCV6eUPrhkRjXYyLw@mail.gmail.com>
	<ef10545e-db46-44f6-aaac-f70bf739c6ba@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c35152f7bed10519d2525b
X-Trace: ger.gmane.org 1435766012 16631 80.91.229.3 (1 Jul 2015 15:53:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 1 Jul 2015 15:53:32 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDIIVO6GQULBB6UZ2CWAKGQEWCLJPCQ@isocpp.org Wed Jul 01 17:53:31 2015
Return-path: <std-proposals+bncBDIIVO6GQULBB6UZ2CWAKGQEWCLJPCQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f69.google.com ([209.85.215.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDIIVO6GQULBB6UZ2CWAKGQEWCLJPCQ@isocpp.org>)
	id 1ZAKKJ-0001H6-CA
	for gclcip-std-proposals@m.gmane.org; Wed, 01 Jul 2015 17:53:31 +0200
Original-Received: by lagx9 with SMTP id x9sf13310948lag.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 01 Jul 2015 08:53:30 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:content-type: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=EA3ipwihJNkDgm8SoiaWJNnWmP4Q1ru1/6bXAG/FtIE=;
        b=knJpqV4hpzV2nENM/NjBT4PbwB1V9G437ukNwNUiBlfpDo1uyJKMZyIhE/TityunLX
         4hQfA8D5Zl099RM9IJb2UIpNQi+Il/L8hHf6fdDePy7Ao54BzQQn5UMBP1IerqUJYZ0i
         vckPFRGWjSPRBFMa/bwMgSlW1X3uiuscXC0PAvcmorm/SLZEgpiAMvoPEvv8gHJJmNgs
         F9WlQVd7EF48nlNHr27m/dP6sIJETSnf+w4zqJDjlXrAWZrV4ymFAMsnAV5hL4S/jXQb
         5CT78YuKIflyXzdjq67c6E0poN0ZTTRuCGFCxR4NnO8EDlYCYh6TvFY8MQ8NK+ZKaHVR
         P9Zg==
X-Gm-Message-State: ALoCoQmSzHXRe1Dg37vKAT8ZzUgCE8adRtQx8nmssdSlX8xm3+irEd6oZ91ljXl7DfCvkFPzoc0X
X-Received: by 10.112.28.111 with SMTP id a15mr17463094lbh.21.1435766010898;
        Wed, 01 Jul 2015 08:53:30 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.204.168 with SMTP id kz8ls185806lac.105.gmail; Wed, 01 Jul
 2015 08:53:29 -0700 (PDT)
X-Received: by 10.112.72.132 with SMTP id d4mr25951543lbv.1.1435766009696;
        Wed, 01 Jul 2015 08:53:29 -0700 (PDT)
Original-Received: from mail-lb0-x22c.google.com (mail-lb0-x22c.google.com. [2a00:1450:4010:c04::22c])
        by mx.google.com with ESMTPS id q10si2042482lbp.109.2015.07.01.08.53.29
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 01 Jul 2015 08:53:29 -0700 (PDT)
Received-SPF: pass (google.com: domain of dribeas@gmail.com designates 2a00:1450:4010:c04::22c as permitted sender) client-ip=2a00:1450:4010:c04::22c;
Original-Received: by lbnk3 with SMTP id k3so15662954lbn.1
        for <std-proposals@isocpp.org>; Wed, 01 Jul 2015 08:53:29 -0700 (PDT)
X-Received: by 10.152.43.110 with SMTP id v14mr25985976lal.4.1435766009345;
 Wed, 01 Jul 2015 08:53:29 -0700 (PDT)
Original-Sender: dribeas@gmail.com
Original-Received: by 10.152.43.170 with HTTP; Wed, 1 Jul 2015 08:53:29 -0700 (PDT)
In-Reply-To: <ef10545e-db46-44f6-aaac-f70bf739c6ba@isocpp.org>
X-Original-Sender: dibeas@ieee.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of dribeas@gmail.com designates 2a00:1450:4010:c04::22c as permitted
 sender) smtp.mail=dribeas@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:18905
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18905>

--001a11c35152f7bed10519d2525b
Content-Type: text/plain; charset=UTF-8

You could create a free function in the module that does the same, right?

To convert(From f) { return To{ f.a, f.b }; }
....
auto to = convert(getSomeFrom());

On Wed, Jul 1, 2015 at 2:55 PM, Igor Baidiuk <target.san@gmail.com> wrote:

>
>
> On Wednesday, July 1, 2015 at 4:17:23 PM UTC+3, Patrice Roy wrote:
>>
>> What is missing from explicit conversion operators in your mind? For
>> example, what effect do you want to acheive that is not acheived by
>> something like the following?
>>
>> I cannot define conversions as free-standing functions.
> Sometimes it's really useful when you want those conversions, but don't
> want to pollute struct interface, because those conversions are used only
> inside of some module.
>
>
>> #include <string>
>> struct Three
>> {
>>     explicit operator int() const { return 3; }
>>     explicit operator std::string() const { return "three"; }
>> };
>>
>> int main()
>> {
>>     Three three;
>>     auto i = static_cast<int>(three); // yields 3
>>     auto s = static_cast<std::string>(three); // yields
>> std::string("three")
>>     // int j = three; // illegal
>>     // string str = three; // illegal
>> }
>>
>> Cheers!
>>
>> 2015-07-01 7:17 GMT-04:00 Igor Baidiuk <targe...@gmail.com>:
>>
>>> What if we could define
>>> operator static_cast<To>(From const& from)
>>> {
>>>     return { from.a, from.b};
>>> }
>>> // later in code
>>> From from;
>>> auto to = static_cast<To>(from);
>>> as means of non-member, explicit conversion syntax?
>>> So we don't need to write tons of functions like toFoo, toBar, toBaz etc.
>>> Or, allow declaring non-member conversion operators, which are explicit
>>> by default?
>>>
>>> --
>>>
>>> ---
>>> 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 email to std-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> Visit this group at
>>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>>
>>
>>  --
>
> ---
> 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
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

-- 

--- 
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 email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c35152f7bed10519d2525b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">You could create a free function in the module that does t=
he same, right?<br><br>To convert(From f) { return To{ f.a, f.b }; }<br>...=
<br>auto to =3D convert(getSomeFrom());</div><div class=3D"gmail_extra"><br=
><div class=3D"gmail_quote">On Wed, Jul 1, 2015 at 2:55 PM, Igor Baidiuk <s=
pan dir=3D"ltr">&lt;<a href=3D"mailto:target.san@gmail.com" target=3D"_blan=
k">target.san@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr"><span class=3D""><br><br>On Wednesday, July 1, 2015 a=
t 4:17:23 PM UTC+3, Patrice Roy wrote:<blockquote class=3D"gmail_quote" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><div>What is missing from explicit conversion operators=
 in your mind? For example, what effect do you want to acheive that is not =
acheived by something like the following?<br><br></div></div></blockquote><=
/span><div>I cannot define conversions as free-standing functions.<br>Somet=
imes it&#39;s really useful when you want those conversions, but don&#39;t =
want to pollute struct interface, because those conversions are used only i=
nside of some module.<br>=C2=A0<br></div><span class=3D""><blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div>#include &lt;string&gt;<br>str=
uct Three<br>{<br>=C2=A0=C2=A0=C2=A0 explicit operator int() const { return=
 3; }<br>=C2=A0=C2=A0=C2=A0 explicit operator std::string() const { return =
&quot;three&quot;; }<br>};<br><br>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 Thr=
ee three;<br>=C2=A0=C2=A0=C2=A0 auto i =3D static_cast&lt;int&gt;(three); /=
/ yields 3<br>=C2=A0=C2=A0=C2=A0 auto s =3D static_cast&lt;std::string&gt;(=
three); // yields std::string(&quot;three&quot;)<br>=C2=A0=C2=A0=C2=A0 // i=
nt j =3D three; // illegal<br>=C2=A0=C2=A0=C2=A0 // string str =3D three; /=
/ illegal<br>}<br><br></div></div></blockquote><div></div></span><blockquot=
e class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div></div>Cheers!<br></div>=
<div><br><div class=3D"gmail_quote"><span class=3D"">2015-07-01 7:17 GMT-04=
:00 Igor Baidiuk <span dir=3D"ltr">&lt;<a rel=3D"nofollow">targe...@gmail.c=
om</a>&gt;</span>:<br></span><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"=
"><div dir=3D"ltr">What if we could define<br><div style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">opera=
tor</span><span style=3D"color:#000"> </span><span style=3D"color:#008">sta=
tic_cast</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#=
606">To</span><span style=3D"color:#660">&gt;(</span><span style=3D"color:#=
606">From</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">const</span><span style=3D"color:#660">&amp;</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">from</span><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">from</span><span style=3D"color:#660">.</span><span style=3D"col=
or:#000">a</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">from</span><span style=3D"color:#660=
">.</span><span style=3D"color:#000">b</span><span style=3D"color:#660">};<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#800">// lat=
er in code</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#606">From</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">from</span><span style=3D"color:#660">;</span><span style=3D"color:#00=
0"><br></span><span style=3D"color:#008">auto</span><span style=3D"color:#0=
00"> to </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">static_cast</span><span style=3D"col=
or:#660">&lt;</span><span style=3D"color:#606">To</span><span style=3D"colo=
r:#660">&gt;(</span><span style=3D"color:#008">from</span><span style=3D"co=
lor:#660">);</span><span style=3D"color:#000"><br></span></div></code></div=
>as means of non-member, explicit conversion syntax?<br>So we don&#39;t nee=
d to write tons of functions like toFoo, toBar, toBaz etc.<br>Or, allow dec=
laring non-member conversion operators, which are explicit by default?<span=
><font color=3D"#888888"><br></font></span></div></span><span><font color=
=3D"#888888"><span class=3D"">

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br></span>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<span class=3D""><br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" rel=3D"nofollow" target=3D"_blank">http://groups.google.com=
/a/isocpp.org/group/std-proposals/</a>.<br>
</span></font></span></blockquote></div><br></div>
</blockquote></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
<br>
--- <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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c35152f7bed10519d2525b--

.
