Topic: Grouping placeholders for bind
Author: tomaszkam@gmail.com
Date: Tue, 23 Jul 2013 13:40:57 -0700 (PDT)
Raw View
------=_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> 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(&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> a) is_placeholder<T> would=
be used to determine if the type is placeholder<br> b) placeholder_p=
ositions<T,N> will provide zero (please see motivation bellow) or mor=
e index of argument to be forwarder (index should be 1based to<br> &nb=
sp; 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> index of all arguments). The =
placeholder position should be derived from std::integer_sequence<std::s=
ize_t, ...> class in case when is_placeholder<T>::value<br> =
is true.<br> 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;"> &nbs=
p; template<typename T, std::size_t N><br> struct placeh=
older_positions :<br> </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<std::size_t, std::is_placeholder<T>::value><br> &nbs=
p; {}</span><br> so for the single argu=
ment placeholder, is_placeholder can be used in the same way as today, but =
bind depend only for </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> <font face=3D"arial,sans-ser=
if">to get argument to forward.<br><br>2. There should be 2 group pla=
ceholders defined in the standard:<br> a) _all, that will=
forward all arguments, definition using proposed specializations would be:=
<br> <font face=3D"courier new,monospac=
e">template<><br> struct is_placeholder<_all> : std=
::true_type {};<br><br> </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<std::size_t N><=
br> 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<_all, N><br>&=
nbsp; : shift<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<=
;std::size_t, N>, 1> {} <br><span style=3D"font-family: arial,sans-se=
rif;"> b) _from<N> that will forward arguments all argume=
nts form Nth. The _from<N> should be ill formed if number of argument=
s is less than N. For exactly N-1<br> 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.<br> &nbs=
p; 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"> <font face=3D"co=
urier new,monospace">template<std::size_t N><br> struct i=
s_placeholder<_from<N>> : 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"> </font></font></span></span></span><span style=3D"font-fam=
ily: courier new,monospace;"><br> 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<std::size_t N><br=
> 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<_all, ArgCount>=
<br> : enable_if<</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 <=3D N,</span>=
</span></span> <br> &=
nbsp; shift<=
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<std::size_t, ArgCount - N + =
1>, N> {}<br><span style=3D"font-family: arial,sans-serif;"> 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> all a=
nd from. Most of the code that uses bind, looks like:<br><span style=3D"fon=
t-family: courier new,monospace;"> 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; std::bind(f, _1, a, _2);</span><br> 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> named all or from and cause the crash of bind=
.. That it the reason I choosed _all and _from instead, which look pre=
tty uniform with _1. Another solution would be<br> 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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<br />
------=_Part_756_14761284.1374612057352--
.
Author: Xeo <hivemaster@hotmail.de>
Date: Tue, 23 Jul 2013 14:22:39 -0700 (PDT)
Raw View
------=_Part_847_7630750.1374614559631
Content-Type: text/plain; charset=ISO-8859-1
I have played around with implementing such an `easy_bind` (as I call it)
before, which can be found here <http://stackoverflow.com/a/15025170/500104>and is really easy (especially in C++14 when you can just use
`decltype(auto)` for the return type).
You will notice that I used `std::function<R(FArgs...)>` instead of a
generic `class F` in the public interface - the reason is that not all
function objects can have the number of their parameters determined. The
`operator()` may be either overloaded, templated, or both, rendering any
attempt to get a specific signature moot.
Of course, the overhead (if actually there) of `std::function` is likely
unwanted in such a general purpose function. However, there are really only
two callable entities where the signature can be inspected:
function-pointers and member-function-pointers. As such, with the interface
of `std::bind` today, you can't really do better than that.
The second argument N would mean actual number of argument provided to
> invocation of the bind (so we cane genereate index of all arguments)
>
Here is the problem. First, the number of (bound) arguments passed to
`std::bind` is irrelevant for the placeholders that are needed; these need,
if anything, to be determined from the passed callable object. Second,
notice that Jonathan specifically did *not* mention any indices. This
`std::placeholders::all` form requires a very different implementation that
simply forwards all arguments that are passed at the invocation of the
returned bind object. It cannot be done with the current interface and
numbered placeholders, simply because some functions don't even *have* an
upper bound on the number of arguments - variadic templates say hello.
On Tuesday, July 23, 2013 10:40:57 PM UTC+2, toma...@gmail.com wrote:
>
> 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_847_7630750.1374614559631
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I have played around with implementing such an `easy_bind` (as I call it) b=
efore, which can be found <a href=3D"http://stackoverflow.com/a/15025170/50=
0104">here</a> and is really easy (especially in C++14 when you can just us=
e `decltype(auto)` for the return type).<br><br>You
will notice that I used `std::function<R(FArgs...)>` instead of a
generic `class F` in the public interface - the reason is that not all=20
function objects can have the number of their parameters determined. The
`operator()` may be either overloaded, templated, or both, rendering=20
any attempt to get a specific signature moot.<br><br>Of course, the=20
overhead (if actually there) of `std::function` is likely unwanted in=20
such a general purpose function. However, there are really only two callabl=
e entities where the signature can be inspected:=20
function-pointers and member-function-pointers. As such, with the interface=
of `std::bind` today, you can't really do better than that.<br><br><blockq=
uote style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 20=
4, 204); padding-left: 1ex;" class=3D"gmail_quote"><span><span style=3D"col=
or:rgb(34,34,34)">The second argument N would mean actual number of argumen=
t provided to invocation of the bind (so we cane genereate index of all arg=
uments)</span></span><br></blockquote><div>Here is the problem. First, the =
number of (bound) arguments passed to `std::bind` is irrelevant for the pla=
ceholders that are needed; these need, if anything, to be determined from t=
he passed callable object. Second, notice that Jonathan specifically did <i=
>not</i> mention any indices. This `std::placeholders::all` form requires a=
very different implementation that simply forwards all arguments that are =
passed at the invocation of the returned bind object. It cannot be done wit=
h the current interface and numbered placeholders, simply because some func=
tions don't even *have* an upper bound on the number of arguments - variadi=
c templates say hello.<br></div><br>On Tuesday, July 23, 2013 10:40:57 PM U=
TC+2, toma...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
In the discussion of <a href=3D"https://groups.google.com/a/isocpp.org/foru=
m/?fromgroups#!topic/std-proposals/CxpGVY1APcs" target=3D"_blank">mem_fn wi=
th additional parameter</a> <span><span style=3D"color:rgb(34,34,34)">Jonat=
han Wakely proposed the idea of new placeholder type named all,<br> th=
at will forward all of the arguments to the functor and suggested that it c=
ould be extended to more generic group placeholders.<br>Example:<br><span s=
tyle=3D"font-family:courier new,monospace">auto f =3D std::bind(&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 suppl=
ied arguments to the functor, <br>so:<br><span style=3D"font-family:courier=
new,monospace">f(t1, t2, ..., tN)</span><br>Will be equivalent to:<br><spa=
n style=3D"font-family:courier new,monospace">a.foo</span></span></span><sp=
an><span style=3D"color:rgb(34,34,34)"><span style=3D"font-family:courier n=
ew,monospace">(t1, t2, ..., tN) </span><br>//I assumed a is an object in th=
e example, but it will support anything that INVOKE does.<br><br>I would li=
ke to share my thoughts on the approach how such placeholders can be define=
d in the extend-able manner (so the user can define<br>its own group placeh=
olders).<br><br>1. At this moment the standard defines the is_placeholder t=
raits that provides both functionality: informs that the type placeholder a=
nd provides <br>the number of forwarder argument. I would like to split tha=
t behavior, to 2 classes:<br> a) is_placeholder<T> would be use=
d to determine if the type is placeholder<br> b) placeholder_position=
s<T,N> will provide zero (please see motivation bellow) or more index=
of argument to be forwarder (index should be 1based to<br> &nbs=
p; uniform with standard bind). The second argument N would mea=
n actual number of argument provided to invocation of the bind (so we cane =
genereate<br> index of all arguments). The placeho=
lder position should be derived from std::integer_sequence<std::<wbr>siz=
e_t, ...> class in case when is_placeholder<T>::value<br> &n=
bsp; is true.<br> c) to main the backward compatibility the, default =
implementation of </span></span><span><span style=3D"color:rgb(34,34,34)">p=
laceholder_positions would be:<br><span style=3D"font-family:courier new,mo=
nospace"> template<typename T, std::size_t N><br>&n=
bsp; struct placeholder_positions :<br> </=
span></span></span><span><span style=3D"color:rgb(34,34,34)"><span style=3D=
"font-family:courier new,monospace">std::integer_sequence<std::<wbr>size=
_t, std::is_placeholder<T>::value><br> {}</span>=
<br> so for the single argument placeholder, =
is_placeholder can be used in the same way as today, but bind depend only f=
or </span></span><span style=3D"font-family:courier new,monospace">p<=
/span><span><span style=3D"color:rgb(34,34,34)"><span style=3D"font-family:=
courier new,monospace">laceholder_positions<br> <font face=3D"arial,s=
ans-serif">to get argument to forward.<br><br>2. There should be 2 gr=
oup placeholders defined in the standard:<br> a) _all, th=
at will forward all arguments, definition using proposed specializations wo=
uld be:<br> <font face=3D"courier new,m=
onospace">template<><br> struct is_placeholder<_all>=
; : std::true_type {};<br><br> </font></font></span></span></sp=
an><span style=3D"font-family:courier new,monospace">t</span><span><span st=
yle=3D"color:rgb(34,34,34)"><span style=3D"font-family:courier new,monospac=
e">emplate<std::size_t N><br> struct </span></span></span=
><span><span style=3D"color:rgb(34,34,34)"><span style=3D"font-family:couri=
er new,monospace">placeholder_positions<_all, N><br>  =
; : shift<s</span></span></span><span><span style=3D"color:rgb(34,=
34,34)"><span style=3D"font-family:courier new,monospace">td::make_integer_=
<wbr>sequence<std::size_t, N>, 1> {} <br><span style=3D"font-famil=
y:arial,sans-serif"> b) _from<N> that will forward argume=
nts all arguments form Nth. The _from<N> should be ill formed if numb=
er of arguments is less than N. For exactly N-1<br> &nb=
sp; arguments there should be empty sequence generated - if there is need t=
o be sure that at least N arguments, then _N, _from<N+1> may be used.=
<br> Implementation:<br></span></span><=
/span></span><span><span style=3D"color:rgb(34,34,34)"><span style=3D"font-=
family:courier new,monospace"><font face=3D"arial,sans-serif"> &=
nbsp; <font face=3D"courier new,monospace">template<st=
d::size_t N><br> struct is_placeholder<_from<N>>=
: std::true_type {};</font></font></span></span></span><br><span><span sty=
le=3D"color:rgb(34,34,34)"><span style=3D"font-family:courier new,monospace=
"><font face=3D"arial,sans-serif"><font face=3D"courier new,monospace">&nbs=
p; </font></font></span></span></span><span style=3D"font-family:cour=
ier new,monospace"><br> t</span><span><span style=3D"color:rgb(=
34,34,34)"><span style=3D"font-family:courier new,monospace">emplate<std=
::size_t N><br> struct </span></span></span><span><span styl=
e=3D"color:rgb(34,34,34)"><span style=3D"font-family:courier new,monospace"=
>placeholder_positions<_all, ArgCount><br> : =
enable_if<</span></span></span><span><span style=3D"color:rgb(34,34,34)"=
><span style=3D"font-family:courier new,monospace"><span><span style=3D"col=
or:rgb(34,34,34)"><span style=3D"font-family:courier new,monospace">ArgCoun=
t + 1 <=3D N,</span></span></span> <br> &n=
bsp;  =
; shift<s</span></span></span><span><span style=3D"color:rgb=
(34,34,34)"><span style=3D"font-family:courier new,monospace">td::make_inte=
ger_<wbr>sequence<std::size_t, ArgCount - N + 1>, N> {}<br><=
span style=3D"font-family:arial,sans-serif"> c) The user can define i=
ts own placeholders group via specializations.</span><br><br><font face=3D"=
arial,sans-serif">3. I would define new placeholder in the namespace std::p=
laceholders, but that may lead to the some annoying problems to the user if=
there where named simply<br> all and from. Most of the c=
ode that uses bind, looks like:<br><span style=3D"font-family:courier new,m=
onospace"> using namespace </span></font></span></span></=
span><span><span style=3D"color:rgb(34,34,34)"><span style=3D"font-family:c=
ourier new,monospace"><font face=3D"arial,sans-serif"><span><span style=3D"=
color:rgb(34,34,34)"><span style=3D"font-family:courier new,monospace"><fon=
t face=3D"arial,sans-serif"><span style=3D"font-family:courier new,monospac=
e">std::placeholders;<br> std::bind(f, _1, a, _2);</span>=
<br> While there is really low possibility to have variab=
les named _1, _2, ... in the user code, there is pretty much a chance that =
the user code would define viarbles<br> 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<=
br> to define it in the different namespace.<br><br>What =
are you thoughts about this idea.<br></font></span></span></span></font></s=
pan></span></span></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<br />
------=_Part_847_7630750.1374614559631--
.
Author: tomaszkam@gmail.com
Date: Tue, 23 Jul 2013 22:47:30 -0700 (PDT)
Raw View
------=_Part_376_302164.1374644850981
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
W dniu wtorek, 23 lipca 2013 23:22:39 UTC+2 u=BFytkownik Xeo napisa=B3:
>
> I have played around with implementing such an `easy_bind` (as I call it)=
=20
> before, which can be found here<http://stackoverflow.com/a/15025170/50010=
4>and is really easy (especially in C++14 when you can just use=20
> `decltype(auto)` for the return type).
>
> You will notice that I used `std::function<R(FArgs...)>` instead of a=20
> generic `class F` in the public interface - the reason is that not all=20
> function objects can have the number of their parameters determined. The=
=20
> `operator()` may be either overloaded, templated, or both, rendering any=
=20
> attempt to get a specific signature moot.
>
> Of course, the overhead (if actually there) of `std::function` is likely=
=20
> unwanted in such a general purpose function. However, there are really on=
ly=20
> two callable entities where the signature can be inspected:=20
> function-pointers and member-function-pointers. As such, with the interfa=
ce=20
> of `std::bind` today, you can't really do better than that.
>
> The second argument N would mean actual number of argument provided to=20
>> invocation of the bind (so we cane genereate index of all arguments)
>>
> Here is the problem. First, the number of (bound) arguments passed to=20
> `std::bind` is irrelevant for the placeholders that are needed; these nee=
d,=20
> if anything, to be determined from the passed callable object. Second,=20
> notice that Jonathan specifically did *not* mention any indices. This=20
> `std::placeholders::all` form requires a very different implementation th=
at=20
> simply forwards all arguments that are passed at the invocation of the=20
> returned bind object. It cannot be done with the current interface and=20
> numbered placeholders, simply because some functions don't even *have* an=
=20
> upper bound on the number of arguments - variadic templates say hello.
>
The sentence should look like (I ommited it part while writing):
The second argument N would mean actual number of argument provided to=20
the operator() of functor created as a result of bind.
The expansion of the group placeholder is only done with the context when=
=20
bind result is invoked so the number of arguments that was passed to it=20
would be enough to generate indicies that will forward alll of the and=20
placeholders::all can be implemented.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_376_302164.1374644850981
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
<br><br>W dniu wtorek, 23 lipca 2013 23:22:39 UTC+2 u=BFytkownik Xeo napisa=
=B3:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">I have played around with =
implementing such an `easy_bind` (as I call it) before, which can be found =
<a href=3D"http://stackoverflow.com/a/15025170/500104" target=3D"_blank">he=
re</a> and is really easy (especially in C++14 when you can just use `declt=
ype(auto)` for the return type).<br><br>You
will notice that I used `std::function<R(FArgs...)>` instead of a
generic `class F` in the public interface - the reason is that not all=20
function objects can have the number of their parameters determined. The
`operator()` may be either overloaded, templated, or both, rendering=20
any attempt to get a specific signature moot.<br><br>Of course, the=20
overhead (if actually there) of `std::function` is likely unwanted in=20
such a general purpose function. However, there are really only two callabl=
e entities where the signature can be inspected:=20
function-pointers and member-function-pointers. As such, with the interface=
of `std::bind` today, you can't really do better than that.<br><br><blockq=
uote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,20=
4);padding-left:1ex" class=3D"gmail_quote"><span><span style=3D"color:rgb(3=
4,34,34)">The second argument N would mean actual number of argument provid=
ed to invocation of the bind (so we cane genereate index of all arguments)<=
/span></span><br></blockquote><div>Here is the problem. First, the number o=
f (bound) arguments passed to `std::bind` is irrelevant for the placeholder=
s that are needed; these need, if anything, to be determined from the passe=
d callable object. Second, notice that Jonathan specifically did <i>not</i>=
mention any indices. This `std::placeholders::all` form requires a very di=
fferent implementation that simply forwards all arguments that are passed a=
t the invocation of the returned bind object. It cannot be done with the cu=
rrent interface and numbered placeholders, simply because some functions do=
n't even *have* an upper bound on the number of arguments - variadic templa=
tes say hello.</div></blockquote><div>The sentence should look like (I ommi=
ted it part while writing):<br> The second argument N would mean actu=
al number of argument provided to the operator() of functor created as a re=
sult of bind.<br>The expansion of the group placeholder is only done with t=
he context when bind result is invoked so the number of arguments that was =
passed to it would be enough to generate indicies that will forward alll of=
the and placeholders::all can be implemented.<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<br />
------=_Part_376_302164.1374644850981--
.
Author: tomaszkam@gmail.com
Date: Sat, 27 Jul 2013 03:40:27 -0700 (PDT)
Raw View
------=_Part_37_12298667.1374921627853
Content-Type: text/plain; charset=ISO-8859-1
> The second argument N would mean actual number of argument provided to
>> invocation of the bind (so we cane genereate index of all arguments)
>>
> Here is the problem. First, the number of (bound) arguments passed to
> `std::bind` is irrelevant for the placeholders that are needed; these need,
> if anything, to be determined from the passed callable object. Second,
> notice that Jonathan specifically did *not* mention any indices. This
> `std::placeholders::all` form requires a very different implementation that
> simply forwards all arguments that are passed at the invocation of the
> returned bind object. It cannot be done with the current interface and
> numbered placeholders, simply because some functions don't even *have* an
> upper bound on the number of arguments - variadic templates say hello.
>
> It can be done and to prove it I have prepared the almost standard
conforming implementation of bind function in C++11 (tested on clang 3.2
and gcc 4.8.1) that supports customizable group placeholders. The thinks
that are missing are:
1. bind<R> - because its add nothing and implementation would be trivial
2. volatile, const volatile overloads of bind invoke operator - this is
cause by lack of std::get overload for tuples which such qualification
(const is supported).
3. _from<N> is not variable template (not supported)
The implementation can be found on:
https://github.com/tomaszkam/proposals/tree/master/bind.
Firstly the test cases can be found in test.cpp<https://github.com/tomaszkam/proposals/blob/master/bind/test.cpp>.
That test includes varidatic template cases and also covers combination of
group and non group placeholders.
Firstly the new placeholders traits are placed in the file
placeholder_traits.hpp<https://github.com/tomaszkam/proposals/blob/master/bind/placeholder_traits.hpp>.
I decided to include new is_placeholder that forwards to
std::is_placeholder traits to be sure that new group placeholders won't
work with std::bind. You may also see default implementation of
placeholder_positions that provides backward compatibility with single
argument placeholders definied using only std::is_placeholder. To mark bind
expression the std::is_bind_expression is used.
The implementation of bind expression is placed in file bind.hpp<https://github.com/tomaszkam/proposals/blob/master/bind/bind.hpp>.
This implementation has no hardcoded placeholders types and depends only on
placeholder traits.
The definition of actual grouping placeholders can be found at
placeholders.hpp<https://github.com/tomaszkam/proposals/blob/master/bind/placeholders.hpp>.
The _from<N> is at this point alias template but should be changed to
variable template in future.
Are there any interest in defining group placeholders for the bind? If so I
think the ability to define custom group placeholders by the user is must
have, to avoid exponential grow of bind implementation. In the proposed
approach implementation of _group<2, 3, 7> placeholder (which may be found
pretty usefull) would look like:
template<std::size_t.... Is>
struct group_placeholder {};
template<std::size_t.... Is>
struct is_placeholder<group_placeholder<Is...>> : true_type {};
template<std::size_t.... Is, std::size_t ArgCount>
struct placeholder_positions<group_placeholder<Is...>, ArgCount> :
integral_sequence<std::size_t, Is...>
{
//static assert to avoid check if all Is are less ArgCount would be
recomended but no actually needed.
};
namespace placeholders
{
template<std::size_t.... Is>
group_placeholder<Is....> _group;
};
--
---
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_37_12298667.1374921627853
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><blockquote style=3D"margi=
n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex=
" class=3D"gmail_quote"><span><span style=3D"color:rgb(34,34,34)">The secon=
d argument N would mean actual number of argument provided to invocation of=
the bind (so we cane genereate index of all arguments)</span></span><br></=
blockquote><div>Here is the problem. First, the number of (bound) arguments=
passed to `std::bind` is irrelevant for the placeholders that are needed; =
these need, if anything, to be determined from the passed callable object. =
Second, notice that Jonathan specifically did <i>not</i> mention any indice=
s. This `std::placeholders::all` form requires a very different implementat=
ion that simply forwards all arguments that are passed at the invocation of=
the returned bind object. It cannot be done with the current interface and=
numbered placeholders, simply because some functions don't even *have* an =
upper bound on the number of arguments - variadic templates say hello.<br><=
/div><br></blockquote><div>It can be done and to prove it I have prepared t=
he almost standard conforming implementation of bind function in C++11 (tes=
ted on clang 3.2 and gcc 4.8.1) that supports customizable group placeholde=
rs. The thinks that are missing are:<br> 1. bind<R> - because i=
ts add nothing and implementation would be trivial<br> 2. volatile, c=
onst volatile overloads of bind invoke operator - this is cause by lack of =
std::get overload for tuples which such qualification (const is supported).=
<br> 3. _from<N> is not variable template (not supported)<br>Th=
e implementation can be found on: <a href=3D"https://github.com/tomaszkam/p=
roposals/tree/master/bind">https://github.com/tomaszkam/proposals/tree/mast=
er/bind</a>.<br><br>Firstly the test cases can be found in <a href=3D"https=
://github.com/tomaszkam/proposals/blob/master/bind/test.cpp">test.cpp</a>. =
That test includes varidatic template cases and also covers combination of =
group and non group placeholders.<br><br>Firstly the new placeholders trait=
s are placed in the file <a href=3D"https://github.com/tomaszkam/proposals/=
blob/master/bind/placeholder_traits.hpp">placeholder_traits.hpp</a>. I deci=
ded to include new is_placeholder that forwards to std::is_placeholde=
r traits to be sure that new group placeholders won't work with std::bind. =
You may also see default implementation of placeholder_positions that provi=
des backward compatibility with single argument placeholders definied using=
only std::is_placeholder. To mark bind expression the std::is_bind_express=
ion is used.<br><br>The implementation of bind expression is placed in file=
<a href=3D"https://github.com/tomaszkam/proposals/blob/master/bind/bind.hp=
p">bind.hpp</a>. This implementation has no hardcoded placeholders types an=
d depends only on placeholder traits.<br><br>The definition of actual group=
ing placeholders can be found at <a href=3D"https://github.com/tomaszkam/pr=
oposals/blob/master/bind/placeholders.hpp">placeholders.hpp</a>. The _from&=
lt;N> is at this point alias template but should be changed to variable =
template in future.<br><br><br>Are there any interest in defining group pla=
ceholders for the bind? If so I think the ability to define custom group pl=
aceholders by the user is must have, to avoid exponential grow of bind impl=
ementation. In the proposed approach implementation of _group<2, 3, 7>=
; placeholder (which may be found pretty usefull) would look like:<br><span=
style=3D"font-family: courier new,monospace;"><br>template<std::size_t.=
.... Is><br>struct group_placeholder {};<br><br>template<std::size_t..=
... Is><br>struct is_placeholder<group_placeholder<Is...>> : =
true_type {};<br><br>template<std::size_t.... Is, std::size_t ArgCount&g=
t;<br>struct placeholder_positions<group_placeholder<Is...>, ArgCo=
unt> : integral_sequence<std::size_t, Is...> <br>{<br> =
//static assert to avoid check if all Is are less ArgCount would be =
recomended but no actually needed.<br>};<br><br>namespace placeholders<br>{=
<br> template<std::size_t.... Is><br> group_p=
laceholder<Is....> _group;<br>};</span><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<br />
------=_Part_37_12298667.1374921627853--
.