当前位置:网站首页>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
边栏推荐
- Solaris 10网络服务
- Four sorts: bubble, select, insert, count
- What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
- Replace() function
- Customized version of cacti host template
- Shift EC20 mode and switch
- Day7 list and dictionary jobs
- 试题库管理系统–数据库设计[通俗易懂]
- Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
- Jemeter script recording
猜你喜欢
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Postman interface test
Automatic translation between Chinese and English
Send a request using paste raw text
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Foreach (system.out:: println) usage
SQL greatest() function instance detailed example
Elevator dispatching (pairing project) ②
os. Path built-in module
Analysis function in SQL
随机推荐
本地Mysql忘记密码的修改方法(windows)
Fundamentals of database operation
os. Path built-in module
Climb Phoenix Mountain on December 19, 2021
Simple understanding of string
About the use of URL, href, SRC attributes
Day06 list job
Simple understanding of generics
Introduction of network security research direction of Shanghai Jiaotong University
Performance features focus & JMeter & LoadRunner advantages and disadvantages
I What is security testing
Lvs+kept realizes four layers of load and high availability
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Performance test method
Dos and path
Appscan installation steps
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
No response after heartbeat startup
LxC shared directory permission configuration
LVS+Keepalived实现四层负载及高可用