c++0x 学习笔记之 Function template bind(一)

2014-11-24 13:01:29 · 作者: · 浏览: 0

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">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
分享到: 更多
<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 学习笔记之 range-based for loop wording
下一篇: c++0x 学习笔记之 多线程(1) ― 启动线程
相关文章
C++0x 学习笔记之 Variadic Templates
『21天精通C++』第一周学习笔记
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<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">
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
排行
热门
<scrip