#include<iostream>#include<functional>template<typenameT>voidprint(Tt){std::cout<<t<<std::endl;}intmain(){std::function<void(int)>f=print<int>;f(123);// 输出 123std::function<void(std::string)>g=print<std::string>;g("hello world");// 输出 hello worldreturn0;} ...
printf("%d\n", *p); // 结果: 一串无意义的随机数 //此处function函数中的指针pn只能存活...
template<classF1,classF2>booltest(F1&&f1,std::function<F2>f2){auto*ptr=f2.template target<std...
// function::target example#include <iostream> // std::cout, std::boolalpha#include <functional> // std::function, std::plus, std::minusint my_plus (int a, int b) {return a+b;}int my_minus (int a, int b) {return a-b;}int main () { std::function<int(...
#include <functional>#include <iostream>intf(int,int){return1;}intg(int,int){return2;}voidtest(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...
conststd::type_info&target_type()constnoexcept; (since C++11) Returns the type of the stored function. Parameters (none) Return value typeid(T)if the stored function has typeT, otherwisetypeid(void) Example Run this code #include <functional>#include <iostream>intf(inta){return-a;}voidg(...
若target_type()==typeid(T)则为指向存储的函数的指针,否则为空指针。 示例 运行此代码 #include <functional>#include <iostream>intf(int,int){return1;}intg(int,int){return2;}voidtest(std::function<int(int,int)>const&arg){std::cout<<"test function: ";if(arg.target<std::plus<int>>())...
In the international standard classification, Target function involves: Software development and system documentation, Semiconducting materials, Document imaging applications, Products of non-ferrous metals, Switchgear and controlgear, Furniture, Kitchen equipment, Electrical engineering in general, Applications of...
(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";}intmain(){test(std::function<int(int,int)>(std::plus<int>()));test(std::function<int(int,int)>(std::minus<int>(...
:function<CurlCallback>(std::bind(&NetworkResource::writeFunction,this,_1,_2,_3,_4)).target<...