bind解决函数只能传递一个参数的问题
发布日期:2021-05-12 21:13:56 浏览次数:12 分类:精选文章

本文共 2006 字,大约阅读时间需要 6 分钟。

C++ Lambda ��� bind ������������

Lambda ������������

���������������������������������������������������������������������������������������������������������Lambda���������������������������������������������������������������������

���������������������Lambda���������������������������������������������������������������������������������������������������������


������ bind ������������

bind������������functional������������������������������������������������newcallable������������������������������������������������������

arglist������������������������_n������������������������������������������������������_1������������������������_2���������������������������������������


bind ������

������checksize���������������������������������������������������������3���������bind���������������������������������������check3���������������������checksize���������������������������3���

int size = 3;auto check3 = bind(checksize, _1, size);

���������check3���������������������_1������������������������������������


���������������������������������

������������������������������func1(int a, int b, int c)

auto func2 = bind(func1, _3, _2, _1);

������func2(1,2,3)������������������������

  • func2���������������������func1������������������a
  • ������������������func1������������������b
  • ������������������func1������������������c

������������������������������������������������


������������������

���������������������������������������������������������

int b = 2;auto func3 = bind(func1, _3, b, _1);

���������b������������������func1���������������������������


������������

������������������bind������������������������������������������������������������������������������������

std::ostringstream os;auto iter = std::foreach(    words.begin(), words.end(),    [&os, c](const std::string &s) {        os << s << " ";    });

���������s������������������������������������������������������


������������������������������lambda���bind���������������������������������������������������������������������

上一篇:70.子集II leetcode
下一篇:C++ lambda表达式

发表评论

最新留言

很好
[***.229.124.182]2025年04月15日 02时26分54秒