当前位置:网站首页>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
边栏推荐
- Jemeter script recording
- LVS+Keepalived实现四层负载及高可用
- No response after heartbeat startup
- Exceptions and exception handling
- R built in data set
- Design and common methods of test case documents
- Dos and path
- JMeter correlation technology
- Local MySQL forgot the password modification method (Windows)
- Configure SSH certificate login
猜你喜欢
Jemeter script recording
Introduction to Lichuang EDA
Postman interface test
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
Canoe - the third simulation project - bus simulation-1 overview
Simple understanding of seesion, cookies, tokens
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
JMeter Foundation
QQ group administrators
随机推荐
Analysis function in SQL
Test question bank management system - database design [easy to understand]
2021-10-20
Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
Elevator dispatching (pairing project) ②
Climb Phoenix Mountain on December 19, 2021
Canoe - the third simulation project - bus simulation - 3-2 project implementation
LxC shared directory permission configuration
About the use of URL, href, SRC attributes
Daemon xinted and logging syslogd
51 data analysis post
Process communication and thread explanation
Day06 list job
unit testing
Deepmind proposed a Zuan AI, which specially outputs network attack language
Ten key performance indicators of software applications
Automatic translation between Chinese and English
Summary of automated testing framework
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?