当前位置:网站首页>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
边栏推荐
- Login operation (for user name and password)
- Object. Assign () & JS (= >) arrow function & foreach () function
- 1. Circular nesting and understanding of lists
- Postman interface test
- Application of slice
- Daemon xinted and logging syslogd
- F12 clear the cookies of the corresponding web address
- CAPL: on sysVar_ Update difference on sysvar
- Ten key performance indicators of software applications
- QQ group collection
猜你喜欢

Fundamentals of software testing

Installation of ES plug-in in Google browser

2021 annual summary - it seems that I have done everything except studying hard

QQ group collection

Global function Encyclopedia

Day01 preliminary packet capture

Post man JSON script version conversion

Automatic translation between Chinese and English

JMeter assembly point technology and logic controller

JMeter correlation technology
随机推荐
JMeter common configuration components and parameterization
Getting started with window functions
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
Global function Encyclopedia
Safety testing aspects
How to create a new virtual machine
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
Foreach (system.out:: println) usage
Login operation (for user name and password)
Analysis function in SQL
Data transmission in the network
Elevator dispatching (pairing project) ③
Common system modules and file operations
Regular expression
Polymorphic system summary
LxC shared directory permission configuration
Common built-in modules
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
Introduction of network security research direction of Shanghai Jiaotong University
Solaris 10 network services