220 16645 <da39fc93-2190-415f-969a-05adaf31000a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Zijie He <hzj_jie@hotmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Propose a smart convertor function
Date: Tue, 3 Mar 2015 06:58:16 -0800 (PST)
Lines: 175
Approved: news@gmane.org
Message-ID: <da39fc93-2190-415f-969a-05adaf31000a@isocpp.org>
References: <aa9dad82-6f83-4ccd-93de-7dee3b857a32@isocpp.org>
 <1e329e3e-1c24-4df7-a8a4-8a196e0bc5aa@isocpp.org>
 <42516db7-6c38-43c5-b2e7-f414e6b78139@isocpp.org>
 <79186eb1-219a-46ff-9586-c4a373c3b172@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_70_2024141473.1425394696839"
X-Trace: ger.gmane.org 1425394707 5650 80.91.229.3 (3 Mar 2015 14:58:27 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 3 Mar 2015 14:58:27 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD6IXSMN7QKRBCMY26TQKGQE32FUJHA@isocpp.org Tue Mar 03 15:58:26 2015
Return-path: <std-proposals+bncBD6IXSMN7QKRBCMY26TQKGQE32FUJHA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f200.google.com ([209.85.160.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD6IXSMN7QKRBCMY26TQKGQE32FUJHA@isocpp.org>)
	id 1YSoHB-0005He-U5
	for gclcip-std-proposals@m.gmane.org; Tue, 03 Mar 2015 15:58:26 +0100
Original-Received: by ykbq200 with SMTP id q200sf121126472ykb.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Mar 2015 06:58:18 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=p7e31KHEXrqtrybRcNaWtqtC7B1HZ/CObW0HoShEzAY=;
        b=gxE/Nrp4TC04Br/7joZulkynLV9Lbu4q7pKcfqjAcXwJHq9uUO1o+61Oe/FOi4NoM2
         0b8TN3BV93ceeStIgxhsZoIxhiB5Vm8KujjraW9c6qH37Qb76YCV4pBkLU9oiEvpQTzl
         aX66sE29e40GOGV/r3CLmKmQV69fkqZCijmubwTvaIloOeQWJVVlZGuL8XQ7JZUbdl+u
         TbfS2SMxeTMmSbdsFuPM6YT1u+2hkRkIyQ2pJUOCIyb9TBAerpyxxSk0u54Rywqoh8lu
         XVuMtrUeOAPxPyaeCzQLJDnun0A4jz6jf76ODvrK01nSBl69zNy5D/F1pVO1yggEnfxX
         BXNw==
X-Gm-Message-State: ALoCoQlzHCcSsLLPaUhCm3+HXJ5i2ayHyrJWlAB2P9253yXYH3O21y8pE6f8PHSMe9ocIq2kHdga
X-Received: by 10.140.196.209 with SMTP id r200mr31729526qha.0.1425394698026;
        Tue, 03 Mar 2015 06:58:18 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.149.164 with SMTP id ub4ls40660obb.98.gmail; Tue, 03 Mar
 2015 06:58:17 -0800 (PST)
X-Received: by 10.182.65.169 with SMTP id y9mr226733obs.17.1425394697264;
        Tue, 03 Mar 2015 06:58:17 -0800 (PST)
In-Reply-To: <79186eb1-219a-46ff-9586-c4a373c3b172@isocpp.org>
X-Original-Sender: Hzj_jie@hotmail.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: <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:16645
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/16645>

------=_Part_70_2024141473.1425394696839
Content-Type: multipart/alternative; 
	boundary="----=_Part_71_1457284584.1425394696839"

------=_Part_71_1457284584.1425394696839
Content-Type: text/plain; charset=UTF-8

Sorry, do you really mean c2 = 1; does not use operator=(int)? If there is 
a conversion operator, it will be used, but in the case I have provided, 
the operator= is definitely involved.
And I still cannot quite understand, why you think implicit constructor and 
operator= are the same thing. They are two different functions, while C c = 
1; uses implicit constructor, C c; c = 1; uses operator=. A class may 
implement one of them or both, or none. Some school books mentioned that 
you always should implement operator= (const T&) with T(const T&), but the 
compiler does not force you to do so.

On Tuesday, March 3, 2015 at 2:13:07 PM UTC+8, Nicol Bolas wrote:
>
>
>
> On Monday, March 2, 2015 at 9:28:25 PM UTC-5, Zijie He wrote:
>>
>> The proposal is targeting three different problems,
>> 1. is_assignable is much more than T1 t1 = t2;
>>
>
> Actually, that's line is not an example of is_assignable at all. That 
> statement will never use the assignment operator; it will instead use an 
> appropriate conversion (either via an implicit constructor or via a single 
> implicit conversion operator call).
>  
>
>> 2. As you have mentioned, performance concern. There may be several ways 
>> to convert from T1 to T2, while this implementation can help to select the 
>> best one.
>>
>
> As previously stated, the only performance concern as things currently 
> stand is the rare case of performing a conversion into a live object. And 
> you have yet to explain why this case is important enough to bother with 
> such a change.
>  
>
>> 3. Typically in template programming, usually you do not know the types 
>> of T1 and T2, while there may be several ways to convert from T1 to T2.
>>
>
> There are not "several" ways to convert; there are precisely two: either 
> via initialization of a new value or via copy/move-into-a-live-object. Both 
> ways in C++ use the assignment operator (though the initialization case 
> doesn't call the overload for it). The language supports these cases well 
> enough without template metaprogramming or 'convert_to' or other such stuff.
>
> So what are these "several ways" you keep talking about optimizing for? 
> What are the other alternatives?
>
> Several types may implements constructor, several types may implements 
>> operator=. The behavior will be same, but in the template, you may need to 
>> handle several cases. So this implementation is to separate the irrelevant 
>> logic from this kind of templates.
>>
>
> Nonsense. In a template, you impose some particular requirement on the 
> type. Sans-concepts, this requirement is implicit. If you template needs to 
> "convert" from one type to another, we have an acceptable syntax to do that:
>
> T1 t1 = t2;
>
> There are no performance issues with this. There is no "irrelevant logic" 
> needed to make this work. You don't need any special cases. You simply use 
> the language features.
>
> The user will implement the implicit conversion in T1 or T2 at their 
> leisure, and your template code will adapt to their choice. There are no 
> cases for you to consider. So long as the user has done their jobs in 
> making T1 and T2, this will work.
>
> And if they didn't, then they get a compiler error. As they should.
>
> If you want to be nicer to the user (so the conversions don't have to be 
> implicit), you invoke direct initialization:
>
> T1 t1(t2);
>

-- 

--- 
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/.

------=_Part_71_1457284584.1425394696839
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sorry, do you really mean c2 =3D 1; does not use operator=
=3D(int)? If there is a conversion operator, it will be used, but in the ca=
se I have provided, the operator=3D is definitely involved.<div>And I still=
 cannot quite understand, why you think implicit constructor and operator=
=3D are the same thing. They are two different functions, while C c =3D 1; =
uses implicit constructor, C c; c =3D 1; uses operator=3D. A class may impl=
ement one of them or both, or none. Some school books mentioned that you al=
ways should implement operator=3D (const T&amp;) with T(const T&amp;), but =
the compiler does not force you to do so.</div><br>On Tuesday, March 3, 201=
5 at 2:13:07 PM UTC+8, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><br><br>On Monday, March 2, 2015 at 9:28:25 PM =
UTC-5, Zijie He wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;m=
argin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr">The proposal is targeting three different problems,<div>1. is_assignabl=
e is much more than T1 t1 =3D t2;</div></div></blockquote><div><br>Actually=
, that's line is not an example of is_assignable at all. That statement wil=
l never use
 the assignment operator; it will instead use an appropriate conversion (ei=
ther via an implicit constructor or via a single implicit conversion operat=
or call).<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">2. As you have mentioned, performance concern. There may be severa=
l ways to convert from T1 to T2, while this implementation can help to sele=
ct the best one.<br></div></blockquote><div><br>As previously stated, the o=
nly performance concern as things currently stand is the rare case of perfo=
rming a conversion into a live object. And you have yet to explain why this=
 case is important enough to bother with such a change.<br>&nbsp;</div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>3. Typically in t=
emplate programming, usually you do not know the types of T1 and T2, while =
there may be several ways to convert from T1 to T2.</div></div></blockquote=
><div><br>There are not "several" ways to convert; there are precisely two:=
 either via initialization of a new value or via copy/move-into-a-live-obje=
ct. Both ways in C++ use the assignment operator (though the initialization=
 case doesn't call the overload for it). The language supports these cases =
well enough without template metaprogramming or 'convert_to' or other such =
stuff.<br><br>So what are these "several ways" you keep talking about optim=
izing for? What are the other alternatives?<br><br></div><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>Several types may implements c=
onstructor, several types may implements operator=3D. The behavior will be =
same, but in the template, you may need to handle several cases. So this im=
plementation is to separate the irrelevant logic from this kind of template=
s.<br></div></div></blockquote><div><br>Nonsense. In a template, you impose=
 some particular requirement on the type. Sans-concepts, this requirement i=
s implicit. If you template needs to "convert" from one type to another, we=
 have an acceptable syntax to do that:<br><br>T1 t1 =3D t2;<br><br>There ar=
e no performance issues with this. There is no "irrelevant logic" needed to=
 make this work. You don't need any special cases. You simply use the langu=
age features.<br><br>The user will implement the implicit conversion in T1 =
or T2 at their leisure, and your template code will adapt to their choice. =
There are no cases for you to consider. So long as the user has done their =
jobs in making T1 and T2, this will work.<br><br>And if they didn't, then t=
hey get a compiler error. As they should.<br><br>If you want to be nicer to=
 the user (so the conversions don't have to be implicit), you invoke direct=
 initialization:<br><br>T1 t1(t2);<br></div></div></blockquote></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 />

------=_Part_71_1457284584.1425394696839--
------=_Part_70_2024141473.1425394696839--

.
