220 32791 <1edb48fd-0d4c-478b-816b-6cd9b21b4f0c@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Mingxin Wang <wmx16835vv@163.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: The Proxies - A Language Feature Decoupling
 Implementations from Requirements of Polymorphism
Date: Fri, 16 Jun 2017 18:55:15 -0700 (PDT)
Lines: 216
Approved: news@gmane.org
Message-ID: <1edb48fd-0d4c-478b-816b-6cd9b21b4f0c@isocpp.org>
References: <8d79a013-fe0e-4fb6-8278-d438ae9b4c64@isocpp.org>
 <CAOU91OO5iXoZ1Hf=q7Ux=BuH9C_fFfUz_=xt3DWEAJbrhzOzhA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1833_161804354.1497664515735"
X-Trace: blaine.gmane.org 1497664519 10492 195.159.176.226 (17 Jun 2017 01:55:19 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 17 Jun 2017 01:55:19 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDNMBNHJWIGBBBEYSLFAKGQEJ5KTLVA@isocpp.org Sat Jun 17 03:55:13 2017
Return-path: <std-proposals+bncBDNMBNHJWIGBBBEYSLFAKGQEJ5KTLVA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ot0-f200.google.com ([74.125.82.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDNMBNHJWIGBBBEYSLFAKGQEJ5KTLVA@isocpp.org>)
	id 1dM2xE-0002ML-Lz
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Jun 2017 03:55:12 +0200
Original-Received: by mail-ot0-f200.google.com with SMTP id 37sf19059486otu.13
        for <gclcip-std-proposals@m.gmane.org>; Fri, 16 Jun 2017 18:55:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=nVF3NRuLQiYe9GFoXoStWoyxWH1EgYuKy7k772i8XB4=;
        b=pUrVdfvswXLimL4b7I4/6CobExx8vOArV7FEBDJ97c+tS9nV+sjXL4m72wjR8X7XYY
         1NtN7sK+FTJkLgO1onk1N5OuGbF5foof0AFRT4gd1OwePmc/kEg0yMV4qGvuanuHDHvo
         X8ykvdalGT9XobuJ1Qu6bIIvAGI5m5//cXZXTVpES72/ZN4fP6pmcFEwEBQ83ROd0N5g
         KMrmhzI/3bDqMt+Jo7gkg6LZRGghGd1uzjLxEb3lm/5gEFlAK6A87Q0qV3EziRyuUF3l
         ulNYlzJ34JqS7KuDvM+N33eboJ+6HqKaTVNVe6LlYWHGozWOIUJwIwggWb6rmN35X5++
         v9DQ==
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: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=nVF3NRuLQiYe9GFoXoStWoyxWH1EgYuKy7k772i8XB4=;
        b=cLWISdHXummkWkawzNi6MwVrvAjvsQYD5qKHGN0s7wHKObHm//P5KRGo+NBFISP/CX
         maDzVIP12zyXoyRZWTNPwIRr6Qs6I4oFCHLbtr7qDWi0vQ1KbwJN5yDEe2zxg2ia5Nnv
         7plRIygJWMwq+znLuxE0YBO613CJppMdQSbBuc0h2wAaaWzI9vG6rVewToJDxDXCPKNs
         3KihuFNU60e61EGOMSNALe20prrKgP4yqTSKX4LwOBOqhYrZCdI+uMDS3kgc6BrIMka6
         iqVrpSu99j9BU8W0WtJbenRndWsaqTCaNegaG8YB+Ve9l1FhN9kfQXDrQ6D4LsEFKYkU
         4Jcw==
X-Gm-Message-State: AKS2vOzoccqrM+xWRHmewJd43+IsQwPJbZYsPylR4sk0myBsOk/3PqEw
	sUJ2u2tKM/EL8mUQ
X-Received: by 10.157.4.117 with SMTP id 108mr7038275otc.44.1497664517578;
        Fri, 16 Jun 2017 18:55:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.45.110 with SMTP id v101ls2594493ota.15.gmail; Fri, 16 Jun
 2017 18:55:16 -0700 (PDT)
X-Received: by 10.157.47.207 with SMTP id b15mr428967otd.20.1497664516406;
        Fri, 16 Jun 2017 18:55:16 -0700 (PDT)
In-Reply-To: <CAOU91OO5iXoZ1Hf=q7Ux=BuH9C_fFfUz_=xt3DWEAJbrhzOzhA@mail.gmail.com>
X-Original-Sender: wmx16835vv@163.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:32791
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32791>

------=_Part_1833_161804354.1497664515735
Content-Type: multipart/alternative; 
	boundary="----=_Part_1834_1629482302.1497664515736"

------=_Part_1834_1629482302.1497664515736
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Saturday, June 17, 2017 at 12:16:24 AM UTC+8, Klaim - Jo=C3=ABl Lamotte =
wrote:
>
>
> On 13 June 2017 at 15:49, Mingxin Wang <wmx16...@163.com <javascript:>>=
=20
> wrote:
>
>> *Class template proxy*
>>
>> Expression "proxy<I, W>" is a well-formed type if I is a pure virtual=20
>> class (without a virtual destructor) and W is a type meets the Wrapper=
=20
>> requirements defined above.
>>
>> "proxy<I, W>" is MoveConstructible if W is MoveConstructible, while=20
>> "proxy<I, W>" is CopyConstructible if W is CopyConstructible.
>>
>> Providing p is a value of "proxy<I, W>" and i is a pointer of I,=20
>> "p.f(args...)" shall be a valid expression if "(*i).f(args...)" is a val=
id=20
>> expression, where f is any valid function name (including operator=20
>> overloads) and "args..." is any valid combination of values of any type.
>>
>
>
> Could you clarify: if a system want to take anything that have the=20
> interface described by I, how should it=20
>
>     some_system.take_it_and_do_something( ??? object );
>
> I believe this would be really too restrictive:
>
>     some_system.take_it_and_do_something( proxy<I,W> object );
>
> Because it would force the user code to use only one ownership strategy=
=20
> for anything passed to this function.
> In my experience, I want the system to ignore if it will own or not the=
=20
> object, let the user decide, as long as
> the proxy is usable as a normal object.
> In my opinion, the fact that the real object is shared or not should not=
=20
> be imposed by the system consuming the proxy.
>

Any type that has the required expressions specified by I and can be used=
=20
to construct the wrapper specified by W, can be implicitly convertible to=
=20
proxy<I, W>. It is true that users are responsible to specify ownership=20
strategies in type declarations, but this only happens in a certain=20
context. When there is no need for polymorphism, I prefer to declare a=20
function as a template. Here is an example use case for proxies and=20
templates:

template <class Task =3D SharedProxy<Callable<void()>>>
class CompositTask {
 public:
  template <class... Args>
  void emplace(Args&&... args) {
    data_.emplace_back(std::forward<Args>(args)...);
  }

  void operator()() {
    for (auto& t : data_) t();
  }

 private:
  std::vector<Task> data_;
};

Proxy usually works well with templates. The code above is a class template=
=20
with a default type, which satisfies the requirements specified by=20
Callable<void()>. Providing there is another function declared as follows:

void submit_a_task(DeepProxy<Callable<void()>> task);

The following code is well-formed for client code:

CompositTask<> c;
c.emplace([] { puts("Lambda Expression"); });
c.emplace(std::bind([](const char* x) { puts(x); }, "Bind Expression"));
c.emplace(c);
submit_a_task(c);

Every conversion is done implicitly.
=20

>
> Jo=C3=ABl Lamotte
>
>
Mingxin Wang

--=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/1edb48fd-0d4c-478b-816b-6cd9b21b4f0c%40isocpp.or=
g.

------=_Part_1834_1629482302.1497664515736
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, June 17, 2017 at 12:16:24 AM UTC+8, Klaim - J=
o=C3=ABl Lamotte wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div><br><div class=3D"gmail_quote">On 13 June 2017 at 15:49, Min=
gxin Wang <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" g=
df-obfuscated-mailto=3D"2L3Zqt6cAAAJ" rel=3D"nofollow" onmousedown=3D"this.=
href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;java=
script:&#39;;return true;">wmx16...@163.com</a>&gt;</span> wrote:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1=
px solid rgb(204,204,204);padding-left:1ex"><div><font size=3D"4"><b>Class =
template proxy</b></font></div><div><br></div><div>Expression &quot;proxy&l=
t;I, W&gt;&quot; is a well-formed type if I is a pure virtual class (withou=
t a virtual destructor) and W is a type meets the Wrapper requirements defi=
ned above.</div><div><br></div><div>&quot;proxy&lt;I, W&gt;&quot; is MoveCo=
nstructible if W is MoveConstructible, while &quot;proxy&lt;I, W&gt;&quot; =
is CopyConstructible if W is CopyConstructible.</div><div><br></div><div>Pr=
oviding p is a value of &quot;proxy&lt;I, W&gt;&quot; and i is a pointer of=
 I, &quot;p.f(args...)&quot; shall be a valid expression if &quot;(*i).f(ar=
gs...)&quot; is a valid expression, where f is any valid function name (inc=
luding operator overloads) and &quot;args...&quot; is any valid combination=
 of values of any type.</div><div></div></blockquote></div><br><br></div><d=
iv>Could you clarify: if a system want to take anything that have the inter=
face described by I, how should it=C2=A0</div><div><br></div><div>=C2=A0 =
=C2=A0 some_system.take_it_and_do_<wbr>something( ??? object );</div><div><=
br></div><div>I believe this would be really too restrictive:</div><div><br=
></div><div>=C2=A0 =C2=A0 some_system.take_it_and_do_<wbr>something( proxy&=
lt;I,W&gt; object );</div><div><br></div><div>Because it would force the us=
er code to use only one ownership strategy for anything passed to this func=
tion.</div><div>In my experience, I want the system to ignore if it will ow=
n or not the object, let the user decide, as long as</div><div>the proxy is=
 usable as a normal object.</div><div>In my opinion, the fact that the real=
 object is shared or not should not be imposed by the system consuming the =
proxy.</div></div></blockquote><div><br></div><div>Any type that has the re=
quired expressions specified by I and can be used to construct the wrapper =
specified by W, can be implicitly convertible to proxy&lt;I, W&gt;. It is t=
rue that users are responsible to specify ownership strategies in type decl=
arations, but this only happens in a certain context. When there is no need=
 for polymorphism, I prefer to declare a function as a template. Here is an=
 example use case for proxies and templates:</div><div><br></div><div><div =
class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><font color=3D"#660066"><div class=
=3D"subprettyprint">template &lt;class Task =3D SharedProxy&lt;Callable&lt;=
void()&gt;&gt;&gt;</div><div class=3D"subprettyprint">class CompositTask {<=
/div><div class=3D"subprettyprint">=C2=A0public:</div><div class=3D"subpret=
typrint">=C2=A0 template &lt;class... Args&gt;</div><div class=3D"subpretty=
print">=C2=A0 void emplace(Args&amp;&amp;... args) {</div><div class=3D"sub=
prettyprint">=C2=A0 =C2=A0 data_.emplace_back(std::forward&lt;Args&gt;(args=
)...);</div><div class=3D"subprettyprint">=C2=A0 }</div><div class=3D"subpr=
ettyprint"><br></div><div class=3D"subprettyprint">=C2=A0 void operator()()=
 {</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 for (auto&amp; t : data=
_) t();</div><div class=3D"subprettyprint">=C2=A0 }</div><div class=3D"subp=
rettyprint"><br></div><div class=3D"subprettyprint">=C2=A0private:</div><di=
v class=3D"subprettyprint">=C2=A0 std::vector&lt;Task&gt; data_;</div><div =
class=3D"subprettyprint">};</div></font></div></code></div><br>Proxy usuall=
y works well with templates. The code above is a class template with a defa=
ult type, which satisfies the requirements specified by Callable&lt;void()&=
gt;. Providing there is another function declared as follows:</div><div><br=
></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, =
187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#660=
066">void submit_a_task(DeepProxy&lt;Callable&lt;void()&gt;&gt; task);</fon=
t><br></div></code></div><br>The following code is well-formed for client c=
ode:</div><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1=
px solid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(2=
50, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
div class=3D"subprettyprint">CompositTask&lt;&gt; c;</div><div class=3D"sub=
prettyprint">c.emplace([] { puts(&quot;Lambda Expression&quot;); });</div><=
div class=3D"subprettyprint">c.emplace(std::bind([](const char* x) { puts(x=
); }, &quot;Bind Expression&quot;));</div><div class=3D"subprettyprint">c.e=
mplace(c);</div><div class=3D"subprettyprint">submit_a_task(c);</div></div>=
</code></div><br>Every conversion is done implicitly.</div><div>=C2=A0</div=
><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></d=
iv><div>Jo=C3=ABl Lamotte</div><div><br></div></div></blockquote><div><br><=
/div><div>Mingxin Wang</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/1edb48fd-0d4c-478b-816b-6cd9b21b4f0c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1edb48fd-0d4c-478b-816b-6cd9b21b4f0c=
%40isocpp.org</a>.<br />

------=_Part_1834_1629482302.1497664515736--

------=_Part_1833_161804354.1497664515735--

.
