220 26562 <CANu6V4UKX2sUOv+b_H8M4oegpG2OYL6rY13mkvG8qOKdzO6_ZQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: auto type deduction for *_cast return argument
Date: Tue, 5 Jul 2016 17:18:12 +0200
Lines: 154
Approved: news@gmane.org
Message-ID: <CANu6V4UKX2sUOv+b_H8M4oegpG2OYL6rY13mkvG8qOKdzO6_ZQ@mail.gmail.com>
References: <58140e46-2adc-4eac-8f51-72d3685cdf0b@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=94eb2c05ce5e45ef750536e4f631
X-Trace: ger.gmane.org 1467731903 13802 80.91.229.3 (5 Jul 2016 15:18:23 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 5 Jul 2016 15:18:23 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCQPNCEZSQNBBOE7565QKGQETDHK6QI@isocpp.org Tue Jul 05 17:18:19 2016
Return-path: <std-proposals+bncBCQPNCEZSQNBBOE7565QKGQETDHK6QI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f71.google.com ([209.85.220.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCQPNCEZSQNBBOE7565QKGQETDHK6QI@isocpp.org>)
	id 1bKS78-0000gm-RO
	for gclcip-std-proposals@m.gmane.org; Tue, 05 Jul 2016 17:18:19 +0200
Original-Received: by mail-pa0-f71.google.com with SMTP id b13sf403878485pat.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 05 Jul 2016 08:18:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:date:message-id:subject:from: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=ShkwdwXcjK+cMo8G39P0PIky+Oahqsl/yY7OJ03ZwWE=;
        b=dE7nK/bbXHoXKNblbk7XMUMHV/uzM+zif/m7idAD96+zkK9rclFr0MTWeiEF659emy
         PsdeSo62oqkB1XWx5gtkz+2DZ+YjImkWHCYlW7uGCrdU+vt9lAgqNN4Sk6Z3i+wqtdlu
         qfue8M5SNZVYqDyF8j8yhe/KNfJM/7CQ5Du5FyQV49aNgnXzKAiHZkAklabWik2umOfZ
         LiVyvdqpQg6j4qPBMi/9H762UYXKm39REezygGmAO4BjUMvgKaFRYkIV1XRIJTH3sLrB
         BtrbLmtqvCUxKLUjc3QQcdhIwEnkBHD3xBoW0nE1p9izcED3wEpLQaKEUR4WJy/s4hGo
         mbBA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from: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=ShkwdwXcjK+cMo8G39P0PIky+Oahqsl/yY7OJ03ZwWE=;
        b=K3uAqRmL7VVHGxZcM6jiVCSGMO7Q/FbJWoBZYUWZ8XwCFkT8BkvB5v0RkeunXPzWqH
         XbHNNBLKfKQq3pR8iqf7pSd+3GKrbBB+L+jNKfzOUlUJZ1nVmaTxoBxlrk0IiMJmaQQC
         y20yTTXsUan/XEghVa/OxFD4P0ilrUExS6hoE+p5I8B4kn5TEl/brQKBm6N0XUy0bxtZ
         copGyGsEXZN6arabY8f+SpMafdoRhvgR/UrNM7svfpSX3+q8dBGfr2a2eKoZLHNMYqdb
         TY9LTfnO4KLMBCaO6Hzy+80g+XKLKHn2lDbk8CQceT8gNMtJYXNqEfETyTWqxNKnoX27
         xIWQ==
X-Gm-Message-State: ALyK8tJm2S2UdxcrdQBtS4G6R2GSAJibriTgifuK08I4lxknKWrNUwdOfzaYbPVbui/G4w==
X-Received: by 10.66.158.39 with SMTP id wr7mr13041644pab.35.1467731897601;
        Tue, 05 Jul 2016 08:18:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.174.199 with SMTP id n68ls1932216ioo.104.gmail; Tue, 05
 Jul 2016 08:18:16 -0700 (PDT)
X-Received: by 10.107.133.101 with SMTP id h98mr13372562iod.16.1467731896581;
        Tue, 05 Jul 2016 08:18:16 -0700 (PDT)
Original-Received: from mail-it0-x231.google.com (mail-it0-x231.google.com. [2607:f8b0:4001:c0b::231])
        by mx.google.com with ESMTPS id 138si455040itf.7.2016.07.05.08.18.16
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 05 Jul 2016 08:18:16 -0700 (PDT)
Received-SPF: pass (google.com: domain of schaub.johannes@googlemail.com designates 2607:f8b0:4001:c0b::231 as permitted sender) client-ip=2607:f8b0:4001:c0b::231;
Original-Received: by mail-it0-x231.google.com with SMTP id j185so9647104ith.1
        for <std-proposals@isocpp.org>; Tue, 05 Jul 2016 08:18:16 -0700 (PDT)
X-Received: by 10.36.158.195 with SMTP id p186mr14796356itd.64.1467731895772;
 Tue, 05 Jul 2016 08:18:15 -0700 (PDT)
Original-Received: by 10.107.16.102 with HTTP; Tue, 5 Jul 2016 08:18:12 -0700 (PDT)
Original-Received: by 10.107.16.102 with HTTP; Tue, 5 Jul 2016 08:18:12 -0700 (PDT)
In-Reply-To: <58140e46-2adc-4eac-8f51-72d3685cdf0b@isocpp.org>
X-Original-Sender: schaub.johannes@googlemail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@googlemail.com;       spf=pass (google.com: domain of
 schaub.johannes@googlemail.com designates 2607:f8b0:4001:c0b::231 as
 permitted sender) smtp.mailfrom=schaub.johannes@googlemail.com;
       dmarc=pass (p=QUARANTINE dis=NONE) header.from=googlemail.com
X-Original-From: Johannes Schaub <schaub.johannes@googlemail.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:26562
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26562>

--94eb2c05ce5e45ef750536e4f631
Content-Type: text/plain; charset=UTF-8

It is not obvious that the type of the target is chosen, of you omit the
type. Another choice is that no conversion at all is done (the type is the
operand type) which is also sensible.

Therefore i do not like this change, it is ambiguous.

Am 05.07.2016 09:47 schrieb <xavinaar@gmail.com>:
>
> When using reinterpret_cast, dynamic_cast, static_cast and const_cast,
you always have to specify type explicitly, yet it almost always can be
deduced from the context.
>
> Consider an example:
>
>     void someFunc(Derived *d);
>
>     // ...
>
>     const Base *cbase = new Base;
>     const Derived *cderived = dynamic_cast<const Derived *>(cbase);
>     Derived *derived = const_cast<Derived *>(cderived);
>     someFunc(derived);
>
> Having knowledge of desired argument type (such as explicitly declared
variable type or function argument type) we can auto-deduce desired return
types. My suggestion is to make type specialization for cast operations
optional in such cases which will result in much cleaner code:
>
>     const Base *cbase = new Base;
>     someFunc(dynamic_cast(const_cast(cbase)));
>
> Furthermore, as soon as const_cast is mostly used to cast const
pointers/references to mutable ones (backwards conversion is implicit), I
also suggest to define default behavior of const_cast as to return
non-const pointer/reference to argument type, such as:
>
>     const Base *cbase = new Base;
>     auto base = const_cast(cbase); // type of base is "Base"
>
> This rule can also be generalized to any templated function:
>
>     template <typename T>
>     T someFunc();
>
>     // ...
>
>     int i = someFunc(); // will invoke someFunc<int>();
>
> --
> 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/58140e46-2adc-4eac-8f51-72d3685cdf0b%40isocpp.org
..

-- 
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/CANu6V4UKX2sUOv%2Bb_H8M4oegpG2OYL6rY13mkvG8qOKdzO6_ZQ%40mail.gmail.com.

--94eb2c05ce5e45ef750536e4f631
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">It is not obvious that the type of the target is chosen, of =
you omit the type. Another choice is that no conversion at all is done (the=
 type is the operand type) which is also sensible.</p>
<p dir=3D"ltr">Therefore i do not like this change, it is ambiguous.</p>
<p dir=3D"ltr">Am 05.07.2016 09:47 schrieb &lt;<a href=3D"mailto:xavinaar@g=
mail.com">xavinaar@gmail.com</a>&gt;:<br>
&gt;<br>
&gt; When using reinterpret_cast, dynamic_cast, static_cast and const_cast,=
 you always have to specify type explicitly, yet it almost always can be de=
duced from the context.<br>
&gt;<br>
&gt; Consider an example:<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 void someFunc(Derived *d);<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 // ...<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 const Base *cbase =3D new Base;<br>
&gt; =C2=A0=C2=A0=C2=A0 const Derived *cderived =3D dynamic_cast&lt;const D=
erived *&gt;(cbase);<br>
&gt; =C2=A0=C2=A0=C2=A0 Derived *derived =3D const_cast&lt;Derived *&gt;(cd=
erived);<br>
&gt; =C2=A0=C2=A0=C2=A0 someFunc(derived);<br>
&gt;<br>
&gt; Having knowledge of desired argument type (such as explicitly declared=
 variable type or function argument type) we can auto-deduce desired return=
 types. My suggestion is to make type specialization for cast operations op=
tional in such cases which will result in much cleaner code:<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 const Base *cbase =3D new Base;<br>
&gt; =C2=A0=C2=A0=C2=A0 someFunc(dynamic_cast(const_cast(cbase)));<br>
&gt;<br>
&gt; Furthermore, as soon as const_cast is mostly used to cast const pointe=
rs/references to mutable ones (backwards conversion is implicit), I also su=
ggest to define default behavior of const_cast as to return non-const point=
er/reference to argument type, such as:<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 const Base *cbase =3D new Base;<br>
&gt; =C2=A0=C2=A0=C2=A0 auto base =3D const_cast(cbase); // type of base is=
 &quot;Base&quot;<br>
&gt;<br>
&gt; This rule can also be generalized to any templated function:<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 template &lt;typename T&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 T someFunc();<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 // ...<br>
&gt;<br>
&gt; =C2=A0=C2=A0=C2=A0 int i =3D someFunc(); // will invoke someFunc&lt;in=
t&gt;();<br>
&gt;<br>
&gt; -- <br>
&gt; You received this message because you are subscribed to the Google Gro=
ups &quot;ISO C++ Standard - Future Proposals&quot; group.<br>
&gt; To unsubscribe from this group and stop receiving emails from it, send=
 an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
&gt; To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
&gt; To view this discussion on the web visit <a href=3D"https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/58140e46-2adc-4eac-8f51-72d3685c=
df0b%40isocpp.org">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/58140e46-2adc-4eac-8f51-72d3685cdf0b%40isocpp.org</a>.<br>
</p>

<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/CANu6V4UKX2sUOv%2Bb_H8M4oegpG2OYL6rY1=
3mkvG8qOKdzO6_ZQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANu6V4UKX2sUOv=
%2Bb_H8M4oegpG2OYL6rY13mkvG8qOKdzO6_ZQ%40mail.gmail.com</a>.<br />

--94eb2c05ce5e45ef750536e4f631--

.
