Topic: Standard function templates for creating wrapper
Author: =?UTF-8?B?0JLQu9Cw0LTQuNGB0LvQsNCyINCa0L7Qu9C+0YLQstC40L0=?= <vlad.kolotvin@gmail.com>
Date: Thu, 3 Jan 2013 05:06:55 -0800 (PST)
Raw View
------=_Part_377_640682.1357218415503
Content-Type: text/plain; charset=ISO-8859-1
Im my opinion std::bind and std::mem_fn must return std::function. What you
think about this?
--
------=_Part_377_640682.1357218415503
Content-Type: text/html; charset=ISO-8859-1
Im my opinion std::bind and std::mem_fn must return std::function. What you think about this?
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_377_640682.1357218415503--
.
Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Thu, 3 Jan 2013 14:08:28 +0100
Raw View
On Thu, Jan 3, 2013 at 2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=
=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD
<vlad.kolotvin@gmail.com> wrote:
> Im my opinion std::bind and std::mem_fn must return std::function. What y=
ou
> think about this?
>
> --
>
>
>
I think there is no benefit. Perhaps you could care to explain what
benefit you perceive to be gained from this?
Mit freundlichen Gr=C3=BC=C3=9Fen,
Martinho
--=20
.
Author: =?UTF-8?B?0JLQu9Cw0LTQuNGB0LvQsNCyINCa0L7Qu9C+0YLQstC40L0=?= <vlad.kolotvin@gmail.com>
Date: Thu, 3 Jan 2013 05:18:55 -0800 (PST)
Raw View
------=_Part_26_8004272.1357219135907
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
We can easily identify types of arguments of functor.
Example:
std::map<uint16_t,std::function<void (const std::vector<uint8_t>&)>>=20
unpackers;
template<typename... Args> void set_on_packet(uint16_t packet_id,const=20
std:function<void (Args...)>& callback) {
std::function<void (const std::vector<uint8_t>&)> unpacker =3D=20
[](const std::vector<uint8_t>& data) {
binary_reader reader(data);
callback(unpack(reader)...);
}
unpackers.emplace(std::make_pair(packet_id,unpacker));
}
=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 3 =D1=8F=D0=BD=D0=B2=D0=B0=D1=
=80=D1=8F 2013 =D0=B3., 17:08:28 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R. Martinho=20
Fernandes =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Thu, Jan 3, 2013 at 2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=
=BB=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD=20
> <vlad.k...@gmail.com <javascript:>> wrote:=20
> > Im my opinion std::bind and std::mem_fn must return std::function. What=
=20
> you=20
> > think about this?=20
> >=20
> > --=20
> >=20
> >=20
> >=20
>
> I think there is no benefit. Perhaps you could care to explain what=20
> benefit you perceive to be gained from this?=20
>
> Mit freundlichen Gr=C3=BC=C3=9Fen,=20
>
> Martinho=20
>
--=20
------=_Part_26_8004272.1357219135907
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
We can easily identify types of arguments of functor.<div><br></div><div>Ex=
ample:</div><div>std::map<uint16_t,std::function<void (const std::vec=
tor<uint8_t>&)>> unpackers;</div><div><br></div><div>templa=
te<typename... Args> void set_on_packet(uint16_t packet_id,const std:=
function<void (Args...)>& callback) {</div><div> &nbs=
p;std::function<void (const std::vector<uint8_t>&)> un=
packer =3D [](const std::vector<uint8_t>& data) {</div><div>=
binary_reader reader(data);</div><div> &n=
bsp; callback(unpack(reader)...);</div><div> }</=
div><div> unpackers.emplace(std::make_pair(packet_id,unpacker)=
);</div><div>}</div><div><br>=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 3 =
=D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 2013 =D0=B3., 17:08:28 UTC+4 =D0=
=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R. Ma=
rtinho Fernandes =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;">On Thu, Jan 3, 2013 at 2:06 PM, =D0=92=D0=BB=
=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=
=D0=B2=D0=B8=D0=BD
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
t0iFtFWGUWwJ">vlad.k...@gmail.com</a>> wrote:
<br>> Im my opinion std::bind and std::mem_fn must return std::function.=
What you
<br>> think about this?
<br>>
<br>> --
<br>>
<br>>
<br>>
<br>
<br>I think there is no benefit. Perhaps you could care to explain what
<br>benefit you perceive to be gained from this?
<br>
<br>Mit freundlichen Gr=C3=BC=C3=9Fen,
<br>
<br>Martinho
<br></blockquote></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_26_8004272.1357219135907--
.
Author: =?UTF-8?B?0JLQu9Cw0LTQuNGB0LvQsNCyINCa0L7Qu9C+0YLQstC40L0=?= <vlad.kolotvin@gmail.com>
Date: Thu, 3 Jan 2013 05:19:57 -0800 (PST)
Raw View
------=_Part_468_25485926.1357219197495
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
We can easily identify types of arguments of functor.
Example:
std::map<uint16_t,std::function<void (const std::vector<uint8_t>&)>>=20
unpackers;
template<typename... Args> void set_on_packet(uint16_t packet_id,const=20
std:function<void (Args...)>& callback) {
std::function<void (const std::vector<uint8_t>&)> unpacker =3D=20
[](const std::vector<uint8_t>& data) {
binary_reader reader(data);
callback(unpack<Args>(reader)...);
}
unpackers.emplace(std::make_pair(packet_id,unpacker));
}
=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 3 =D1=8F=D0=BD=D0=B2=D0=B0=D1=
=80=D1=8F 2013 =D0=B3., 17:08:28 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R. Martinho=20
Fernandes =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Thu, Jan 3, 2013 at 2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=
=BB=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD=20
> <vlad.k...@gmail.com <javascript:>> wrote:=20
> > Im my opinion std::bind and std::mem_fn must return std::function. What=
=20
> you=20
> > think about this?=20
> >=20
> > --=20
> >=20
> >=20
> >=20
>
> I think there is no benefit. Perhaps you could care to explain what=20
> benefit you perceive to be gained from this?=20
>
> Mit freundlichen Gr=C3=BC=C3=9Fen,=20
>
> Martinho=20
>
--=20
------=_Part_468_25485926.1357219197495
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
We can easily identify types of arguments of functor.<div><br></div><div>Ex=
ample:</div><div>std::map<uint16_t,std::<wbr>function<void (const std=
::vector<uint8_t>&)>> unpackers;</div><div><br></div><div>t=
emplate<typename... Args> void set_on_packet(uint16_t packet_id,const=
std:function<void (Args...)>& callback) {</div><div>  =
; std::function<void (const std::vector<uint8_t>&)>&nb=
sp;<wbr>unpacker =3D [](const std::vector<uint8_t>& data) {<=
/div><div> binary_reader reader(data);</div><div=
> callback(unpack<Args>(reader)...);</div>=
<div> }</div><div> unpackers.emplace(std::make_<w=
br>pair(packet_id,unpacker));</div><div>}</div><br>=D1=87=D0=B5=D1=82=D0=B2=
=D0=B5=D1=80=D0=B3, 3 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 2013 =D0=B3=
.., 17:08:28 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=
=B5=D0=BB=D1=8C R. Martinho Fernandes =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=
=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Thu, Jan 3, 2013 at =
2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2 =D0=9A=D0=
=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
t0iFtFWGUWwJ">vlad.k...@gmail.com</a>> wrote:
<br>> Im my opinion std::bind and std::mem_fn must return std::function.=
What you
<br>> think about this?
<br>>
<br>> --
<br>>
<br>>
<br>>
<br>
<br>I think there is no benefit. Perhaps you could care to explain what
<br>benefit you perceive to be gained from this?
<br>
<br>Mit freundlichen Gr=C3=BC=C3=9Fen,
<br>
<br>Martinho
<br></blockquote>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_468_25485926.1357219197495--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Jan 2013 15:25:13 +0200
Raw View
On 3 January 2013 15:19, =F7=CC=C1=C4=C9=D3=CC=C1=D7 =EB=CF=CC=CF=D4=D7=C9=
=CE <vlad.kolotvin@gmail.com> wrote:
> We can easily identify types of arguments of functor.
> Example:
> std::map<uint16_t,std::function<void (const std::vector<uint8_t>&)>>
> unpackers;
> template<typename... Args> void set_on_packet(uint16_t packet_id,const
> std:function<void (Args...)>& callback) {
> std::function<void (const std::vector<uint8_t>&)> unpacker =3D [](con=
st
> std::vector<uint8_t>& data) {
> binary_reader reader(data);
> callback(unpack<Args>(reader)...);
> }
> unpackers.emplace(std::make_pair(packet_id,unpacker));
> }
It's absolutely not ok for std::bind to return an std::function. The
function object type returned
by std::bind can and does avoid the dispatch overhead that
std::function carries via its
type erasure.
--=20
.
Author: grigorij1981@gmail.com
Date: Thu, 3 Jan 2013 05:25:08 -0800 (PST)
Raw View
------=_Part_408_4100254.1357219508750
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
But how std::bind will indentify types of arguments, current implementation=
=20
does not know them.
It's the assignment to std::function that fixes specific argument types.
=20
E.g.=20
=20
void f(int x, int y);
=20
std::bind(f, _1, _3); // what should be returned?
=20
Regards,
Gregory
=D0=A7=D0=B5=D1=82=D0=B2=D0=B5=D1=80, 3 =D1=81=D1=96=D1=87=D0=BD=D1=8F 2013=
=D1=80. 15:19:57 UTC+2 =D0=BA=D0=BE=D1=80=D0=B8=D1=81=D1=82=D1=83=D0=B2=D0=
=B0=D1=87 =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2 =D0=9A=D0=
=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2:
> We can easily identify types of arguments of functor.
>
> Example:
> std::map<uint16_t,std::function<void (const std::vector<uint8_t>&)>>=20
> unpackers;
>
> template<typename... Args> void set_on_packet(uint16_t packet_id,const=20
> std:function<void (Args...)>& callback) {
> std::function<void (const std::vector<uint8_t>&)> unpacker =3D=20
> [](const std::vector<uint8_t>& data) {
> binary_reader reader(data);
> callback(unpack<Args>(reader)...);
> }
> unpackers.emplace(std::make_pair(packet_id,unpacker));
> }
>
> =D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 3 =D1=8F=D0=BD=D0=B2=D0=B0=D1=
=80=D1=8F 2013 =D0=B3., 17:08:28 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R. Martinho=20
> Fernandes =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>>
>> On Thu, Jan 3, 2013 at 2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=
=BB=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD=20
>> <vlad.k...@gmail.com> wrote:=20
>> > Im my opinion std::bind and std::mem_fn must return std::function. Wha=
t=20
>> you=20
>> > think about this?=20
>> >=20
>> > --=20
>> >=20
>> >=20
>> >=20
>>
>> I think there is no benefit. Perhaps you could care to explain what=20
>> benefit you perceive to be gained from this?=20
>>
>> Mit freundlichen Gr=C3=BC=C3=9Fen,=20
>>
>> Martinho=20
>>
>
--=20
------=_Part_408_4100254.1357219508750
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>But how std::bind will indentify types of arguments, current impl=
ementation does not know them.</div><div>It's the assignment to std::functi=
on that fixes specific argument types.</div><div> </div><div>E.g. </di=
v><div> </div><div>void f(int x, int y);</div><div> </div><div>st=
d::bind(f, _1, _3); // what should be returned?</div><div> </div><div>=
Regards,</div><div>Gregory</div><div><br>=D0=A7=D0=B5=D1=82=D0=B2=D0=B5=D1=
=80, 3 =D1=81=D1=96=D1=87=D0=BD=D1=8F 2013 =D1=80. 15:19:57 UTC+2 =D0=BA=D0=
=BE=D1=80=D0=B8=D1=81=D1=82=D1=83=D0=B2=D0=B0=D1=87 =D0=92=D0=BB=D0=B0=D0=
=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=
=B8=D0=BD =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2:</div><blockquote styl=
e=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(2=
04, 204, 204); border-left-width: 1px; border-left-style: solid;" class=3D"=
gmail_quote">We can easily identify types of arguments of functor.<div><br>=
</div><div>Example:</div><div>std::map<uint16_t,std::<wbr>function<vo=
id (const std::vector<uint8_t>&)>> unpackers;</div><div><br=
></div><div>template<typename... Args> void set_on_packet(uint16_t pa=
cket_id,const std:function<void (Args...)>& callback) {</div><div=
> std::function<void (const std::vector<uint8_t>=
&)> <wbr>unpacker =3D [](const std::vector<uint8_t>&=
amp; data) {</div><div> binary_reader reader(dat=
a);</div><div> callback(unpack<Args>(reade=
r).<wbr>..);</div><div> }</div><div> unpackers.em=
place(std::make_<wbr>pair(packet_id,unpacker));</div><div>}</div><br>=D1=87=
=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 3 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=
=8F 2013 =D0=B3., 17:08:28 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R. Martinho Fernandes =D0=BD=D0=B0=D0=
=BF=D0=B8=D1=81=D0=B0=D0=BB:<blockquote style=3D"margin: 0px 0px 0px 0.8ex;=
padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-widt=
h: 1px; border-left-style: solid;" class=3D"gmail_quote">On Thu, Jan 3, 201=
3 at 2:06 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2 =D0=9A=
=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD
<br><<a>vlad.k...@gmail.com</a>> wrote:
<br>> Im my opinion std::bind and std::mem_fn must return std::function.=
What you
<br>> think about this?
<br>>
<br>> --
<br>>
<br>>
<br>>
<br>
<br>I think there is no benefit. Perhaps you could care to explain what
<br>benefit you perceive to be gained from this?
<br>
<br>Mit freundlichen Gr=C3=BC=C3=9Fen,
<br>
<br>Martinho
<br></blockquote></blockquote>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_408_4100254.1357219508750--
.
Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Thu, 3 Jan 2013 14:25:43 +0100
Raw View
On Thu, Jan 3, 2013 at 2:19 PM, =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=
=D0=B0=D0=B2 =D0=9A=D0=BE=D0=BB=D0=BE=D1=82=D0=B2=D0=B8=D0=BD
<vlad.kolotvin@gmail.com> wrote:
> We can easily identify types of arguments of functor.
>
> Example:
> std::map<uint16_t,std::function<void (const std::vector<uint8_t>&)>>
> unpackers;
>
> template<typename... Args> void set_on_packet(uint16_t packet_id,const
> std:function<void (Args...)>& callback) {
> std::function<void (const std::vector<uint8_t>&)> unpacker =3D [](con=
st
> std::vector<uint8_t>& data) {
> binary_reader reader(data);
> callback(unpack<Args>(reader)...);
> }
> unpackers.emplace(std::make_pair(packet_id,unpacker));
> }
>
Using std::function as function parameters in function templates is
generally not a good idea because you lose type deduction in many
common scenarios. The example will not work with a lambda or with any
other custom function object type, for example.
That said, this sounds like a rather niche use case to me. 99% of the
time you don't want to identify function arguments, you only one to
require that something be *callable* with some set of arguments.
Also note that this essentially breaks std::bind, because it needs to
return a special type so that nested placeholders work fine.
Mit freundlichen Gr=C3=BC=C3=9Fen,
Martinho
--=20
.
Author: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Date: Thu, 3 Jan 2013 14:30:11 +0100
Raw View
--14dae9340bc3faa9e304d2625de8
Content-Type: text/plain; charset=KOI8-U
Content-Transfer-Encoding: quoted-printable
2013/1/3 =F7=CC=C1=C4=C9=D3=CC=C1=D7 =EB=CF=CC=CF=D4=D7=C9=CE <vlad.kolotvi=
n@gmail.com>
> Im my opinion std::bind and std::mem_fn must return std::function. What
> you think about this?
>
> std::bind returns a polymorphic function object while std::function is
monomorphic.
struct sink {
template <class T>
void operator()(const T&) const {}
};
int main() {
auto f =3D std::bind(sink(), std::placeholders::_1);
f(42);
f("hello");
}
This program wouldn't work if std::bind returned std::function.
Roman Perepelitsa.
--=20
--14dae9340bc3faa9e304d2625de8
Content-Type: text/html; charset=KOI8-U
Content-Transfer-Encoding: quoted-printable
2013/1/3 =F7=CC=C1=C4=C9=D3=CC=C1=D7 =EB=CF=CC=CF=D4=D7=C9=CE <span dir=3D"=
ltr"><<a href=3D"mailto:vlad.kolotvin@gmail.com" target=3D"_blank">vlad.=
kolotvin@gmail.com</a>></span><br><div class=3D"gmail_quote"><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">
Im my opinion std::bind and std::mem_fn must return std::function. What you=
think about this?=9A
<span class=3D"HOEnZb"><font color=3D"#888888"><p></p></font></span></block=
quote></div><div>std::bind returns a polymorphic function object while std:=
:function is monomorphic.</div><div><br></div><div><font face=3D"courier ne=
w, monospace">struct sink {</font></div>
<div><font face=3D"courier new, monospace">=9A template <class T></fo=
nt></div><div><font face=3D"courier new, monospace">=9A void operator()(con=
st T&) const {}</font></div><div><font face=3D"courier new, monospace">=
};</font></div>
<div><font face=3D"courier new, monospace"><br></font></div><div><font face=
=3D"courier new, monospace">int main() {</font></div><div><font face=3D"cou=
rier new, monospace">=9A auto f =3D std::bind(sink(), std::placeholders::_1=
);</font></div>
<div><font face=3D"courier new, monospace">=9A f(42);</font></div><div><fon=
t face=3D"courier new, monospace">=9A f("hello");</font></div><di=
v><font face=3D"courier new, monospace">}</font></div><div><br></div><div>T=
his program wouldn't work if std::bind returned std::function.</div>
<div><br></div><div>Roman Perepelitsa.</div>
<p></p>
-- <br />
<br />
<br />
<br />
--14dae9340bc3faa9e304d2625de8--
.
Author: =?UTF-8?B?0JLQu9Cw0LTQuNGB0LvQsNCyINCa0L7Qu9C+0YLQstC40L0=?= <vlad.kolotvin@gmail.com>
Date: Thu, 3 Jan 2013 05:34:52 -0800 (PST)
Raw View
------=_Part_429_19321397.1357220092583
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable
Ok, I did not know that. In this case, my idea is stupid.
=DE=C5=D4=D7=C5=D2=C7, 3 =D1=CE=D7=C1=D2=D1 2013 =C7., 17:30:11 UTC+4 =D0=
=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Roman Perepelitsa=20
=CE=C1=D0=C9=D3=C1=CC:
>
> 2013/1/3 =F7=CC=C1=C4=C9=D3=CC=C1=D7 =EB=CF=CC=CF=D4=D7=C9=CE <vlad.k...@=
gmail.com <javascript:>>
>
>> Im my opinion std::bind and std::mem_fn must return std::function. What=
=20
>> you think about this? =20
>>
>> std::bind returns a polymorphic function object while std::function is=
=20
> monomorphic.
>
> struct sink {
> template <class T>
> void operator()(const T&) const {}
> };
>
> int main() {
> auto f =3D std::bind(sink(), std::placeholders::_1);
> f(42);
> f("hello");
> }
>
> This program wouldn't work if std::bind returned std::function.
>
> Roman Perepelitsa.
>
--=20
------=_Part_429_19321397.1357220092583
Content-Type: text/html; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable
Ok, I did not know that. In this case, my idea is stupid.<br><br>=DE=C5=D4=
=D7=C5=D2=C7, 3 =D1=CE=D7=C1=D2=D1 2013 =C7., 17:30:11 UTC+4 =D0=CF=CC=
=D8=DA=CF=D7=C1=D4=C5=CC=D8 Roman Perepelitsa =CE=C1=D0=C9=D3=C1=CC:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;">2013/1/3 =F7=CC=C1=C4=C9=D3=CC=C1=D7 =
=EB=CF=CC=CF=D4=D7=C9=CE <span dir=3D"ltr"><<a href=3D"javascript:" targ=
et=3D"_blank" gdf-obfuscated-mailto=3D"zpUNaryt3YoJ">vlad.k...@gmail.com</a=
>></span><br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Im my opinion std::bind and std::mem_fn must return std::function. What you=
think about this?
<span><font color=3D"#888888"><p></p></font></span></blockquote></div><div>=
std::bind returns a polymorphic function object while std::function is mono=
morphic.</div><div><br></div><div><font face=3D"courier new, monospace">str=
uct sink {</font></div>
<div><font face=3D"courier new, monospace"> template <class T><=
/font></div><div><font face=3D"courier new, monospace"> void operator=
()(const T&) const {}</font></div><div><font face=3D"courier new, monos=
pace">};</font></div>
<div><font face=3D"courier new, monospace"><br></font></div><div><font face=
=3D"courier new, monospace">int main() {</font></div><div><font face=3D"cou=
rier new, monospace"> auto f =3D std::bind(sink(), std::placeholders:=
:_1);</font></div>
<div><font face=3D"courier new, monospace"> f(42);</font></div><div><=
font face=3D"courier new, monospace"> f("hello");</font></div><div><f=
ont face=3D"courier new, monospace">}</font></div><div><br></div><div>This =
program wouldn't work if std::bind returned std::function.</div>
<div><br></div><div>Roman Perepelitsa.</div>
</blockquote>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_429_19321397.1357220092583--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Jan 2013 16:12:59 +0200
Raw View
On 3 January 2013 15:34, =F7=CC=C1=C4=C9=D3=CC=C1=D7 =EB=CF=CC=CF=D4=D7=C9=
=CE <vlad.kolotvin@gmail.com> wrote:
> Ok, I did not know that. In this case, my idea is stupid.
You're being too harsh on yourself. :)
This paper may shed some light on the design principles:
http://open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1438.htm
It doesn't necessarily emphasize the performance point I raised, though.
I can't find any emphasis on that in boost::bind documentation, either,
but that may also be useful since most of its rationale applies to
std::bind too,
see
http://www.boost.org/doc/libs/1_52_0/libs/bind/bind.html
--=20
.
Author: =?UTF-8?B?0JLQu9Cw0LTQuNGB0LvQsNCyINCa0L7Qu9C+0YLQstC40L0=?= <vlad.kolotvin@gmail.com>
Date: Sun, 6 Jan 2013 06:23:08 -0800 (PST)
Raw View
------=_Part_131_23249649.1357482188751
Content-Type: text/plain; charset=ISO-8859-1
Ok. How i can in this case get types of arguments of wrapped function if
wrapped function isnt template?
Ex.
void func(int a,double b) {
}
auto f = std::bind(func,std::placeholders::_1,std::placeholders::_2);
--
------=_Part_131_23249649.1357482188751
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Ok. How i can in this case get types of arguments of wrapped function if wr=
apped function isnt template?<div><br></div><div>Ex.</div><div><div>void fu=
nc(int a,double b) {</div><div>}</div></div><div><br></div><div>auto f =3D =
std::bind(func,std::placeholders::_1,std::placeholders::_2);<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_131_23249649.1357482188751--
.