std::bind 定义在
|
1
|
#include
|
有两种声明,为
|
1
2
|
template
<
class
F,
class
... BoundArgs>
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
和
|
1
2
|
template
<
class
R,
class
F,
class
... BoundArgs>
unspecified bind(F&& f, BoundArgs&&... bound_args);
|
其中的 … 是 c++0x 引入的 variadic template。
std::bind 最基本的使用如
|
1
2
3
4
5
|
int
f(
int
a,
int
b)
{
return
a + b;
}
std::bind(f, 1, 2 );
|
配合 std::placeholders 则可以产生一些函数对象,比如配合 auto 使用:
|
1
2
3
4
5
6
|
int
g(
int
a,
int
b,
int
c)
{
return
a + b + c;
}
auto gg = std::bind( g, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
注意一下使用方法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include
int
f(
int
a,
int
b)
{
return
a + b;
<script type="text/java script">
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732">
<script type="text/java script" id="bdshell_js">
<script type="text/java script">
var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}};
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
C++0x 学习笔记之 Variadic Templates
<iframe src="http://www.2cto.com/uapi.php tid=89772&catid=339&title=YysrMHgg0afPsLHKvMfWriBGdW5jdGlvbiB0ZW1wbGF0ZSBiaW5k&forward=http://www.2cto.com/kf/201105/89772.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
<scrip
|




