当前位置:网站首页>How do std:: function and function pointer assign values to each other
How do std:: function and function pointer assign values to each other
2022-07-04 11:20:00 【Ascetic monk runnercai】
Let's look at the official code first :
#include <functional>
#include <iostream>
int f(int, int) {
return 1; }
int g(int, int) {
return 2; }
void test(std::function<int(int, int)> const& arg)
{
std::cout << "test function: ";
if (arg.target<std::plus<int>>())
std::cout << "it is plus\n";
if (arg.target<std::minus<int>>())
std::cout << "it is minus\n";
int (*const* ptr)(int, int) = arg.target<int(*)(int, int)>();
if (ptr && *ptr == f)
std::cout << "it is the function f\n";
if (ptr && *ptr == g)
std::cout << "it is the function g\n";
}
int main()
{
test(std::function<int(int, int)>(std::plus<int>()));
test(std::function<int(int, int)>(std::minus<int>()));
test(std::function<int(int, int)>(f));
test(std::function<int(int, int)>(g));
}
After reading it, I found it was very simple , But in practice, you find that you tartget After that, why nullptr
This is because you used bind, It was used bind Then the type changed .
tartget pit
边栏推荐
- JMeter assembly point technology and logic controller
- Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
- QQ one click cookie acquisition
- Fundamentals of database operation
- R built in data set
- If function in SQL
- About the use of URL, href, SRC attributes
- SQL greatest() function instance detailed example
- Canoe - the third simulation project - bus simulation - 3-1 project implementation
- VPS安装Virtualmin面板
猜你喜欢

Attributes and methods in math library

20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13

Introduction to Lichuang EDA

Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)

Detailed array expansion analysis --- take you step by step analysis

Summary of collection: (to be updated)

QQ group collection

Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early

Appscan installation error: unable to install from Net runtime security policy logout appscan solution

SQL greatest() function instance detailed example
随机推荐
Performance test process
Canoe - the third simulation project - bus simulation - 3-1 project implementation
Attributes and methods in math library
Solaris 10网络服务
QQ one click cookie acquisition
Swagger and OpenAPI
Using terminal connection in different modes of virtual machine
Test question bank management system - database design [easy to understand]
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
1. Circular nesting and understanding of lists
Cacti主机模板之定制版
51 data analysis post
Object. Assign () & JS (= >) arrow function & foreach () function
Polymorphic system summary
MBG combat zero basis
Xiaobing · beauty appraisal
Elevator dispatching (pairing project) ④
Deepmind proposed a Zuan AI, which specially outputs network attack language
QQ get group settings
守护进程Xinted和日志记录Syslogd