当前位置:网站首页>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
边栏推荐
- Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
- VPS安装Virtualmin面板
- Canoe-the second simulation project-xvehicle-1 bus database design (idea)
- Design and common methods of test case documents
- Some tips on learning database
- Canoe - the second simulation project -xvihicle1 bus database design (operation)
- software test
- 2021-10-20
- Xiaobing · beauty appraisal
- 3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
猜你喜欢

Application of slice

Simple understanding of seesion, cookies, tokens

Digital simulation beauty match preparation -matlab basic operation No. 6

Canoe - the third simulation project - bus simulation-1 overview

XMIND installation

Ten key performance indicators of software applications

Fundamentals of software testing

Canoe: what is vtsystem

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

Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
随机推荐
3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
Shift EC20 mode and switch
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Canoe: the difference between environment variables and system variables
Introduction to Lichuang EDA
LxC shared directory addition and deletion
Using terminal connection in different modes of virtual machine
Introduction to canoe automatic test system
Notes on writing test points in mind mapping
本地Mysql忘记密码的修改方法(windows)
os. Path built-in module
array_ The contains() function uses
Canoe: the fourth simulation project -- bug debugging experience
Aike AI frontier promotion (2.14)
SQL greatest() function instance detailed example
Interview and lecture summary 1
Canoe: distinguish VT, VN and vteststudio from their development history
51 data analysis post
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download