-
c++11之std::bind和function
- 基本测试代码
-
#include<iostream>
#include<functional>
void func(void)
{
std::cout << __FUNCTION__ << std::endl;
}
void callback(std::function<int(int,char*)> fr)
{
fr(1,"gdg");
}
int strlength(int n,constchar* str)
{
return n + strlen(str);
}
void outPut(int x,int y)
{
std::cout << x <<" "<< y << std::endl;
}
int main()
{
//测试bind
auto fr = std::bind(strlength, std::placeholders::_1, std::placeholders::_2);
//function作为函数参数
callback(fr);
std::bind(strlength,1,"hhha")();
std::bind(strlength, std::placeholders::_1,"hha")(45);//第一个参数从外面传入,第二个参数已经设置好了
std::bind(strlength,23, std::placeholders::_1)("lallaa");//bind里按照函数的参数顺序来
std::bind(strlength, std::placeholders::_2, std::placeholders::_1)("hhafdsf",25);//第一个参数用传入的第二个参数,第二参数用传入的第一个参数
std::bind(strlength, std::placeholders::_1, std::placeholders::_3)(12,45,"fhsafdf");//对,第二个参数没用到
}
-
相关阅读:
day28-描述符应用与类的装饰器
MySQL-快速入门(8)存储过程、存储函数
MySQL-快速入门(7)索引
MySQL-快速入门(6)连接查询、子查询、正则表达式查询、数据的插入删除更新
MySQL-快速入门(5)数据查询-常用关键字、分组查询、聚合函数
MySQL-快速入门(4)MySQL函数
MySQL-快速入门(3)运算符
MySQL-快速入门(2)数据类型
MySQL-快速入门(1)基本数据库、表操作语句
MySql-Mysql技术内幕~SQL编程学习笔记(N)
-
原文地址:https://www.cnblogs.com/dongdongweiwu/p/4743656.html
Copyright © 2020-2023
润新知