220 5525 <81385547-bb12-4ae6-9d12-82aaeb4b5ba0@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: tomaszkam@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Grouping placeholders for bind
Date: Tue, 23 Jul 2013 13:40:57 -0700 (PDT)
Lines: 232
Approved: news@gmane.org
Message-ID: <81385547-bb12-4ae6-9d12-82aaeb4b5ba0@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_756_14761284.1374612057352"
X-Trace: ger.gmane.org 1374612060 1959 80.91.229.3 (23 Jul 2013 20:41:00 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 23 Jul 2013 20:41:00 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDNPVXXG6IGBBWWUXOHQKGQECFAAYIA@isocpp.org Tue Jul 23 22:41:01 2013
Return-path: <std-proposals+bncBDNPVXXG6IGBBWWUXOHQKGQECFAAYIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qe0-f69.google.com ([209.85.128.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDNPVXXG6IGBBWWUXOHQKGQECFAAYIA@isocpp.org>)
	id 1V1jOF-0001S0-8U
	for gclcip-std-proposals@m.gmane.org; Tue, 23 Jul 2013 22:40:59 +0200
Original-Received: by mail-qe0-f69.google.com with SMTP id a11sf10874851qen.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 23 Jul 2013 13:40:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-beenthere:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-google-group-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=RLD3MpZnbN+zviNkk8gKZL3RJ5O7NQk9OnAUJK7YuiE=;
        b=BK2oRRs14sOhxKq4xPSRNUnihvrZTquvbGe56KjmWYFeqjR2mOftaSQy4MJPlRx47f
         pNX3DqgZq+RjHDA6auV5LAO8AAvzmnU71Sqbug+iTx0KrMns5QIOOfie0da79ke8OYtc
         b2c/kjsrnrof+HFj89nEyxp9Zed0GEzo0uN/p2pLGEkE/1l637Rbp/Wz5MXeWIMDQ9/8
         8qUpLu8QcOFXd2P/XjlVv16TskZVgdYeuJRtaVJTZCylPuO1peieSbj2IfZPUEexQynM
         PZEY7E8V7nKvrIefpDdi1kkTGTDZR1Hk6I1MLvMgAhH0FkGtcjDZXp4kjBvbGjoo4nA/
         nvFw==
X-Received: by 10.236.62.132 with SMTP id y4mr15264537yhc.13.1374612058377;
        Tue, 23 Jul 2013 13:40:58 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.82.101 with SMTP id h5ls613639qey.91.gmail; Tue, 23 Jul
 2013 13:40:57 -0700 (PDT)
X-Received: by 10.49.40.167 with SMTP id y7mr1357332qek.36.1374612057781;
        Tue, 23 Jul 2013 13:40:57 -0700 (PDT)
X-Original-Sender: tomaszkam@gmail.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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5525
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5525>

------=_Part_756_14761284.1374612057352
Content-Type: text/plain; charset=ISO-8859-1

In the discussion of mem_fn with additional parameter<https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/CxpGVY1APcs> Jonathan 
Wakely proposed the idea of new placeholder type named all,
 that will forward all of the arguments to the functor and suggested that 
it could be extended to more generic group placeholders.
Example:
auto f = std::bind(&A::foo, a, std::placeholders::all);
Will create functor that will bind an object/pointer a with the function 
member pointer and forwards all supplied arguments to the functor, 
so:
f(t1, t2, ..., tN)
Will be equivalent to:
a.foo(t1, t2, ..., tN) 
//I assumed a is an object in the example, but it will support anything 
that INVOKE does.

I would like to share my thoughts on the approach how such placeholders can 
be defined in the extend-able manner (so the user can define
its own group placeholders).

1. At this moment the standard defines the is_placeholder traits that 
provides both functionality: informs that the type placeholder and provides 
the number of forwarder argument. I would like to split that behavior, to 2 
classes:
  a) is_placeholder<T> would be used to determine if the type is placeholder
  b) placeholder_positions<T,N> will provide zero (please see motivation 
bellow) or more index of argument to be forwarder (index should be 1based to
      uniform with standard bind). The second argument N would mean actual 
number of argument provided to invocation of the bind (so we cane genereate
      index of all arguments). The placeholder position should be derived 
from std::integer_sequence<std::size_t, ...> class in case when 
is_placeholder<T>::value
    is true.
  c) to main the backward compatibility the, default implementation of placeholder_positions 
would be:
    template<typename T, std::size_t N>
    struct placeholder_positions :
       std::integer_sequence<std::size_t, std::is_placeholder<T>::value>
    {}
      so for the single argument placeholder, is_placeholder can be used in 
the same way as today, but bind depend only for  placeholder_positions
  to get argument  to forward.

2. There should be 2 group placeholders defined in the standard:
    a) _all, that will forward all arguments, definition using proposed 
specializations would be:
       template<>
   struct is_placeholder<_all> : std::true_type {};

   template<std::size_t N>
   struct placeholder_positions<_all, N>
     : shift<std::make_integer_sequence<std::size_t, N>, 1> {} 
  b)  _from<N> that will forward arguments all arguments form Nth. The 
_from<N> should be ill formed if number of arguments is less than N. For 
exactly N-1
        arguments there should be empty sequence generated - if there is 
need to be sure that at least N arguments, then _N, _from<N+1> may be used.
       Implementation:
       template<std::size_t N>
   struct is_placeholder<_from<N>> : std::true_type {};
   
   template<std::size_t N>
   struct placeholder_positions<_all, ArgCount>
     : enable_if<ArgCount + 1 <= N,      
                 shift<std::make_integer_sequence<std::size_t, ArgCount - 
N  + 1>, N> {}
  c) The user can define its own placeholders group via specializations.

3. I would define new placeholder in the namespace std::placeholders, but 
that may lead to the some annoying problems to the user if there where 
named simply
    all and from. Most of the code that uses bind, looks like:
    using namespace std::placeholders;
    std::bind(f, _1, a, _2);
    While there is really low possibility to have variables named _1, _2, 
.... in the user code, there is pretty much a chance that the user code 
would define viarbles
    named all or from and cause the crash of bind.  That it the reason I 
choosed _all and _from instead, which look pretty uniform with _1. Another 
solution would be
    to define it in the different namespace.

What are you thoughts about this idea.

-- 

--- 
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_756_14761284.1374612057352
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

In the discussion of <a href=3D"https://groups.google.com/a/isocpp.org/foru=
m/?fromgroups#!topic/std-proposals/CxpGVY1APcs">mem_fn with additional para=
meter</a> <span class=3D"_username"><span style=3D"color: rgb(34, 34, 34);"=
 class=3D"GGYB0KICFKB">Jonathan Wakely proposed the idea of new placeholder=
 type named all,<br>&nbsp;that will forward all of the arguments to the fun=
ctor and suggested that it could be extended to more generic group placehol=
ders.<br>Example:<br><span style=3D"font-family: courier new,monospace;">au=
to f =3D std::bind(&amp;A::foo, a, std::placeholders::all);</span><br>Will =
create functor that will bind an object/pointer a with the function member =
pointer and forwards all supplied arguments to the functor, <br>so:<br><spa=
n style=3D"font-family: courier new,monospace;">f(t1, t2, ..., tN)</span><b=
r>Will be equivalent to:<br><span style=3D"font-family: courier new,monospa=
ce;">a.foo</span></span></span><span class=3D"_username"><span style=3D"col=
or: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-family: cou=
rier new,monospace;">(t1, t2, ..., tN) </span><br>//I assumed a is an objec=
t in the example, but it will support anything that INVOKE does.<br><br>I w=
ould like to share my thoughts on the approach how such placeholders can be=
 defined in the extend-able manner (so the user can define<br>its own group=
 placeholders).<br><br>1. At this moment the standard defines the is_placeh=
older traits that provides both functionality: informs that the type placeh=
older and provides <br>the number of forwarder argument. I would like to sp=
lit that behavior, to 2 classes:<br>&nbsp; a) is_placeholder&lt;T&gt; would=
 be used to determine if the type is placeholder<br>&nbsp; b) placeholder_p=
ositions&lt;T,N&gt; will provide zero (please see motivation bellow) or mor=
e index of argument to be forwarder (index should be 1based to<br>&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; uniform with standard bind). The second argument N wo=
uld mean actual number of argument provided to invocation of the bind (so w=
e cane genereate<br>&nbsp;&nbsp; &nbsp;&nbsp; index of all arguments). The =
placeholder position should be derived from std::integer_sequence&lt;std::s=
ize_t, ...&gt; class in case when is_placeholder&lt;T&gt;::value<br>&nbsp; =
&nbsp; is true.<br>&nbsp; c) to main the backward compatibility the, defaul=
t implementation of </span></span><span class=3D"_username"><span style=3D"=
color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB">placeholder_positions would =
be:<br><span style=3D"font-family: courier new,monospace;">&nbsp;&nbsp;&nbs=
p; template&lt;typename T, std::size_t N&gt;<br>&nbsp; &nbsp; struct placeh=
older_positions :<br>&nbsp; &nbsp; &nbsp;&nbsp; </span></span></span><span =
class=3D"_username"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0K=
ICFKB"><span style=3D"font-family: courier new,monospace;">std::integer_seq=
uence&lt;std::size_t, std::is_placeholder&lt;T&gt;::value&gt;<br>&nbsp;&nbs=
p;&nbsp; {}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; so for the single argu=
ment placeholder, is_placeholder can be used in the same way as today, but =
bind depend only for&nbsp; </span></span><span style=3D"font-family: courie=
r new,monospace;">p</span><span class=3D"_username"><span style=3D"color: r=
gb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-family: courier =
new,monospace;">laceholder_positions<br>&nbsp; <font face=3D"arial,sans-ser=
if">to get argument&nbsp; to forward.<br><br>2. There should be 2 group pla=
ceholders defined in the standard:<br>&nbsp;&nbsp;&nbsp; a) _all, that will=
 forward all arguments, definition using proposed specializations would be:=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face=3D"courier new,monospac=
e">template&lt;&gt;<br>&nbsp;&nbsp; struct is_placeholder&lt;_all&gt; : std=
::true_type {};<br><br>&nbsp;&nbsp; </font></font></span></span></span><spa=
n style=3D"font-family: courier new,monospace;">t</span><span class=3D"_use=
rname"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span =
style=3D"font-family: courier new,monospace;">emplate&lt;std::size_t N&gt;<=
br>&nbsp;&nbsp; struct </span></span></span><span class=3D"_username"><span=
 style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"fon=
t-family: courier new,monospace;">placeholder_positions&lt;_all, N&gt;<br>&=
nbsp;&nbsp;&nbsp;&nbsp; : shift&lt;s</span></span></span><span class=3D"_us=
ername"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span=
 style=3D"font-family: courier new,monospace;">td::make_integer_sequence&lt=
;std::size_t, N&gt;, 1&gt; {} <br><span style=3D"font-family: arial,sans-se=
rif;">&nbsp; b)&nbsp; _from&lt;N&gt; that will forward arguments all argume=
nts form Nth. The _from&lt;N&gt; should be ill formed if number of argument=
s is less than N. For exactly N-1<br>&nbsp; &nbsp; &nbsp; &nbsp; arguments =
there should be empty sequence generated - if there is need to be sure that=
 at least N arguments, then _N, _from&lt;N+1&gt; may be used.<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; Implementation:<br></span></span></span></span><=
span class=3D"_username"><span style=3D"color: rgb(34, 34, 34);" class=3D"G=
GYB0KICFKB"><span style=3D"font-family: courier new,monospace;"><font face=
=3D"arial,sans-serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face=3D"co=
urier new,monospace">template&lt;std::size_t N&gt;<br>&nbsp;&nbsp; struct i=
s_placeholder&lt;_from&lt;N&gt;&gt; : std::true_type {};</font></font></spa=
n></span></span><br><span class=3D"_username"><span style=3D"color: rgb(34,=
 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-family: courier new,mo=
nospace;"><font face=3D"arial,sans-serif"><font face=3D"courier new,monospa=
ce">&nbsp;&nbsp; </font></font></span></span></span><span style=3D"font-fam=
ily: courier new,monospace;"><br>&nbsp;&nbsp; t</span><span class=3D"_usern=
ame"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span st=
yle=3D"font-family: courier new,monospace;">emplate&lt;std::size_t N&gt;<br=
>&nbsp;&nbsp; struct </span></span></span><span class=3D"_username"><span s=
tyle=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-=
family: courier new,monospace;">placeholder_positions&lt;_all, ArgCount&gt;=
<br>&nbsp;&nbsp;&nbsp;&nbsp; : enable_if&lt;</span></span></span><span clas=
s=3D"_username"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFK=
B"><span style=3D"font-family: courier new,monospace;"><span class=3D"_user=
name"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span s=
tyle=3D"font-family: courier new,monospace;">ArgCount + 1 &lt;=3D N,</span>=
</span></span> &nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shift&lt;=
s</span></span></span><span class=3D"_username"><span style=3D"color: rgb(3=
4, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-family: courier new,=
monospace;">td::make_integer_sequence&lt;std::size_t, ArgCount - N&nbsp; + =
1&gt;, N&gt; {}<br><span style=3D"font-family: arial,sans-serif;">&nbsp; c)=
 The user can define its own placeholders group via specializations.</span>=
<br><br><font face=3D"arial,sans-serif">3. I would define new placeholder i=
n the namespace std::placeholders, but that may lead to the some annoying p=
roblems to the user if there where named simply<br>&nbsp;&nbsp;&nbsp; all a=
nd from. Most of the code that uses bind, looks like:<br><span style=3D"fon=
t-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; using namespace </span=
></font></span></span></span><span class=3D"_username"><span style=3D"color=
: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=3D"font-family: couri=
er new,monospace;"><font face=3D"arial,sans-serif"><span class=3D"_username=
"><span style=3D"color: rgb(34, 34, 34);" class=3D"GGYB0KICFKB"><span style=
=3D"font-family: courier new,monospace;"><font face=3D"arial,sans-serif"><s=
pan style=3D"font-family: courier new,monospace;">std::placeholders;<br>&nb=
sp;&nbsp;&nbsp; std::bind(f, _1, a, _2);</span><br>&nbsp;&nbsp;&nbsp; While=
 there is really low possibility to have variables named _1, _2, ... in the=
 user code, there is pretty much a chance that the user code would define v=
iarbles<br>&nbsp;&nbsp;&nbsp; named all or from and cause the crash of bind=
..&nbsp; That it the reason I choosed _all and _from instead, which look pre=
tty uniform with _1. Another solution would be<br>&nbsp;&nbsp;&nbsp; to def=
ine it in the different namespace.<br><br>What are you thoughts about this =
idea.<br></font></span></span></span></font></span></span></span>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
&nbsp;<br />
&nbsp;<br />

------=_Part_756_14761284.1374612057352--

.
