220 37496 <97df4987-b0ed-4080-b58d-fe48b532d1cf@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allowing std::complex's magic permission for
 other types
Date: Tue, 27 Mar 2018 06:57:26 -0700 (PDT)
Lines: 164
Approved: news@gmane.org
Message-ID: <97df4987-b0ed-4080-b58d-fe48b532d1cf@isocpp.org>
References: <a3462649-a7bd-4215-b162-e8fe922df02d@isocpp.org>
 <2f3f1821-385e-4357-bcf4-9a87312853fe@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_18521_1404379364.1522159046543"
X-Trace: blaine.gmane.org 1522158925 21595 195.159.176.226 (27 Mar 2018 13:55:25 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 27 Mar 2018 13:55:25 +0000 (UTC)
Cc: florian.csdt@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBR435HKQKGQEQIPV73Q@isocpp.org Tue Mar 27 15:55:21 2018
Return-path: <std-proposals+bncBCEKFTV6ZUMBBR435HKQKGQEQIPV73Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f197.google.com ([209.85.217.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBR435HKQKGQEQIPV73Q@isocpp.org>)
	id 1f0p4K-0005Uj-NF
	for gclcip-std-proposals@m.gmane.org; Tue, 27 Mar 2018 15:55:20 +0200
Original-Received: by mail-ua0-f197.google.com with SMTP id z27sf15338026uae.23
        for <gclcip-std-proposals@m.gmane.org>; Tue, 27 Mar 2018 06:57:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=PX+FeU9moXqrha4gM9Nx4H6if2CYxzIBXxF2Cg8aIHQ=;
        b=AGFTbK08PBLnXfyqQNCfS8nRcPPDHpuDsp1YtHuwGhBjBN4+P5ncpe/oFU4fi5VOF2
         zDKKhVzStmOth5TynFS3WFq6NiaoI4hZsKPRAz0qo5YdDNu4m+w4N8QWBEEeJQr90K+u
         15nrEfPZFz5YRAxYzlBXP0NUxgqsd4D1M4vG8A9ktA5/hXda3ljXkDL16ruwl7fez/cN
         SKfZNEzGsHcJkv6rXxRmpTNJVzRqr/GvYzbM8PJdWwWqkJFBifXJEC7w8avI2iC2rwj/
         7FJ6XXM6ET263EMF+KNBC1g4ETfPWyP7amsDlKeLOJLRiQjHsIdgxNBnzBYUvcVWHsM7
         w5MA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=PX+FeU9moXqrha4gM9Nx4H6if2CYxzIBXxF2Cg8aIHQ=;
        b=Pq4CjF8IH/z0xlset0kiJUggxfA8/erEZaxQP3feow/EIPP7E5hyG5ajxsqfqvDKob
         osnXPV1FhcWGmWgb7clvBZNHpJKa0eSHqa/pJq5jHztlv6i/xy7Uvr3lU83yNd9/r8Jl
         x95iyT71yt2hPPPK6DFyh8A0nvvqaG+fP4fVccJqif3n6a+sxUn20BylqxmCAe525GBE
         CqHan/A1NnskkSg0ocKx/h0Pnke/DP9o5xTxOvjFxBiSvdCfgqi3pFsEi6hiJhZXJT9q
         FTwdG8ja7MnDdqHMvM90ILu0FlMG0owpQOai3pse49WSh7zUwedqp/e/ZgjJ8Y15snV+
         hcIQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=PX+FeU9moXqrha4gM9Nx4H6if2CYxzIBXxF2Cg8aIHQ=;
        b=EbninqyzZzUARDHKBiUBTD1U9DFz06tGkk0rieIjMeJsp33zoekAtIbOkw7CL/Le1X
         PJykN40kPrImRxiA+Z17f4YcPsjNF/WD4pGd6we6JKN1t4kX/17N7dl3dMbkBM830Bth
         o14yxf1WjlyDyCCa3mirqVurh5Fa2Xah7hsuRqhp/xwL9Gxk97J6no8drWgqXERn5s6K
         +Z+GG2yk6M3xhIwUaMsa55lm/2aiB8AtdS0nEsDnT0XfBMhgEr3DVhPiEljyN7wAez7W
         5LD5zmhqwO4wUbs0l82Tru1YIprAdF2yGwZG6YMI0Ntdt1D0oTtRNmNI2ZfeLXkH5gb1
         P67g==
X-Gm-Message-State: AElRT7Gt1fBjdrQn8TUiPA+28+nYQVko5g83Z4V/4f/t5F8967RDTSUO
	mPuT/L/EyUY3AXembDvpGtIg5w==
X-Google-Smtp-Source: AIpwx495wNaxYaaOJ85gn3mNqVY/p58GY59U6EZD5TAn+0c1Xr5C/4MgpUkuzceFOY7a1m3r1dHurA==
X-Received: by 10.176.112.164 with SMTP id q4mr3839702ual.53.1522159048148;
        Tue, 27 Mar 2018 06:57:28 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.67.2 with SMTP id q2ls700119vka.0.gmail; Tue, 27 Mar 2018
 06:57:27 -0700 (PDT)
X-Received: by 10.31.69.207 with SMTP id s198mr1642875vka.0.1522159046960;
        Tue, 27 Mar 2018 06:57:26 -0700 (PDT)
In-Reply-To: <2f3f1821-385e-4357-bcf4-9a87312853fe@isocpp.org>
X-Original-Sender: jmckesson@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: <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:37496
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37496>

------=_Part_18521_1404379364.1522159046543
Content-Type: multipart/alternative; 
	boundary="----=_Part_18522_882855502.1522159046543"

------=_Part_18522_882855502.1522159046543
Content-Type: text/plain; charset="UTF-8"

On Tuesday, March 27, 2018 at 5:53:23 AM UTC-4, floria...@gmail.com wrote:
>
> I have the impression that people are missing the big picture here.
>
> I see one big problem that can be solved with overloadable 
> reinterpret_cast: smart pointers.
> If you look closely at shared_pointer for instance, you will see:
>
> template <class T, class U>
> std::shared_ptr<T> static_pointer_cast(const std::shared_ptr<U>& r) 
> noexcept;
>
> template <class T, class U>
> std::shared_ptr<T> dynamic_pointer_cast(const std::shared_ptr<U>& r) 
> noexcept;
>
> template <class T, class U>
> std::shared_ptr<T> const_pointer_cast(const std::shared_ptr<U>& r) 
> noexcept;
>
> template <class T, class U>
> std::shared_ptr<T> reinterpret_pointer_cast(const std::shared_ptr<U>& r) 
> noexcept;
>
> If it were possible to overload dynamic_cast const_cast and 
> reinterpret_cast, this would have been unnecessary to have a different 
> interface for shared pointers than for regular pointers.
>

If it were impossible to overload the reference operator, we wouldn't need 
to use `std::addressof` in template programming. But we allowed that, and 
therefore we have to write 99% of our `&value` statements as 
`std::addressof(value)` just to dodge those few users who unwisely overload 
`operator&`.

There are some operations where overloading on user-defined types is 
reasonable. Casting is not one of them (and neither is `operator&`, but 
that ship has sailed). If you need to execute specialized code for a cast, 
then it's not a *cast* at all; it's simply a function call.
 

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/97df4987-b0ed-4080-b58d-fe48b532d1cf%40isocpp.org.

------=_Part_18522_882855502.1522159046543
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, March 27, 2018 at 5:53:23 AM UTC-4, floria...@=
gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">I have the impression that people are missing the big picture here.<br><=
br>I see one big problem that can be solved with overloadable reinterpret_c=
ast: smart pointers.<br>If you look closely at shared_pointer for instance,=
 you will see:<br><br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><s=
pan style=3D"color:#000"></span><span style=3D"color:#008">template</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><sp=
an style=3D"color:#008">class</span><span style=3D"color:#000"> T</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#008">class</span><span style=3D"color:#000"> U</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>std</span><spa=
n style=3D"color:#660">::</span><span style=3D"color:#000">shared_ptr</span=
><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><=
span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> static_poi=
nter_cast</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
8">const</span><span style=3D"color:#000"> std</span><span style=3D"color:#=
660">::</span><span style=3D"color:#000">shared_ptr</span><span style=3D"co=
lor:#660">&lt;</span><span style=3D"color:#000">U</span><span style=3D"colo=
r:#660">&gt;&amp;</span><span style=3D"color:#000"> r</span><span style=3D"=
color:#660">)</span><span style=3D"color:#000"> noexcept</span><span style=
=3D"color:#660">;</span><br><span style=3D"color:#000"><code><span style=3D=
"color:#000"><br></span><span style=3D"color:#008">template</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#008">class</span><span style=3D"color:#000"> T</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">class</span><span style=3D"color:#000"> U</span><span style=3D"c=
olor:#660">&gt;</span><span style=3D"color:#000"><br>std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">shared_ptr</span><span =
style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"> dynamic_pointer_c=
ast</span><span style=3D"color:#660">(</span><span style=3D"color:#008">con=
st</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">:=
:</span><span style=3D"color:#000">shared_ptr</span><span style=3D"color:#6=
60">&lt;</span><span style=3D"color:#000">U</span><span style=3D"color:#660=
">&gt;&amp;</span><span style=3D"color:#000"> r</span><span style=3D"color:=
#660">)</span><span style=3D"color:#000"> noexcept</span><span style=3D"col=
or:#660">;</span></code></span><span style=3D"color:#000"><code><span style=
=3D"color:#660"><code><span style=3D"color:#000"><br><br></span><span style=
=3D"color:#008">template</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#008">class</span><span s=
tyle=3D"color:#000"> T</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"><br>std</span><span style=3D"color:#660">::</span><span sty=
le=3D"color:#000">shared_ptr</span><span style=3D"color:#660">&lt;</span><s=
pan style=3D"color:#000">T</span><span style=3D"color:#660">&gt;</span><spa=
n style=3D"color:#000"> const_pointer_cast</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#008">const</span><span style=3D"color:#000">=
 std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">s=
hared_ptr</span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#000">U</span><span style=3D"color:#660">&gt;&amp;</span><span style=3D"col=
or:#000"> r</span><span style=3D"color:#660">)</span><span style=3D"color:#=
000"> noexcept</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"><br></span></code></span></code></span><code><span style=3D"color:#=
000"><br></span><span style=3D"color:#008">template</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"colo=
r:#008">class</span><span style=3D"color:#000"> T</span><span style=3D"colo=
r:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">class</span><span style=3D"color:#000"> U</span><span style=3D"color:#66=
0">&gt;</span><span style=3D"color:#000"><br>std</span><span style=3D"color=
:#660">::</span><span style=3D"color:#000">shared_ptr</span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"co=
lor:#660">&gt;</span><span style=3D"color:#000"> reinterpret_pointer_cast</=
span><span style=3D"color:#660">(</span><span style=3D"color:#008">const</s=
pan><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">shared_ptr</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#000">U</span><span style=3D"color:#660">&gt=
;&amp;</span><span style=3D"color:#000"> r</span><span style=3D"color:#660"=
>)</span><span style=3D"color:#000"> noexcept</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"><br></span></code></div></code></div=
><br>If it were possible to overload dynamic_cast const_cast and reinterpre=
t_cast, this would have been unnecessary to have a different interface for =
shared pointers than for regular pointers.<br></div></blockquote><div><br>I=
f it were impossible to overload the reference operator, we wouldn&#39;t ne=
ed to use `std::addressof` in template programming. But we allowed that, an=
d therefore we have to write 99% of our `&amp;value` statements as `std::ad=
dressof(value)` just to dodge those few users who unwisely overload `operat=
or&amp;`.<br><br>There are some operations where overloading on user-define=
d types is reasonable. Casting is not one of them (and neither is `operator=
&amp;`, but that ship has sailed). If you need to execute specialized code =
for a cast, then it&#39;s not a <i>cast</i> at all; it&#39;s simply a funct=
ion call.<br>=C2=A0</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/97df4987-b0ed-4080-b58d-fe48b532d1cf%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/97df4987-b0ed-4080-b58d-fe48b532d1cf=
%40isocpp.org</a>.<br />

------=_Part_18522_882855502.1522159046543--

------=_Part_18521_1404379364.1522159046543--

.
