当前位置:网站首页>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
边栏推荐
- Notes on writing test points in mind mapping
- Sys module
- Ten key performance indicators of software applications
- Test question bank management system - database design [easy to understand]
- Safety testing aspects
- Day01 preliminary packet capture
- Install freeradius3 in the latest version of openwrt
- Send a request using paste raw text
- Software testing related resources
- Post man JSON script version conversion
猜你喜欢
Canoe: what is vtsystem
2018 meisai modeling summary +latex standard meisai template sharing
Deepmind proposed a Zuan AI, which specially outputs network attack language
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
OSI seven layer reference model
Summary of Shanghai Jiaotong University postgraduate entrance examination module firewall technology
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
Detailed array expansion analysis --- take you step by step analysis
Serialization oriented - pickle library, JSON Library
JMeter assembly point technology and logic controller
随机推荐
VPS安装Virtualmin面板
Introduction of network security research direction of Shanghai Jiaotong University
1. Circular nesting and understanding of lists
Software testing related resources
Interview and lecture summary 1
Replace() function
2018 meisai modeling summary +latex standard meisai template sharing
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
Aike AI frontier promotion (2.14)
Locust installation
Solaris 10网络服务
Definition and method of string
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
If function in SQL
Heartbeat error attempted replay attack
Some tips on learning database
Local MySQL forgot the password modification method (Windows)
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?