std::function
Simple example of using std::function
#include <functional>
#include <functional>
#include <iostream>
int sum(int x, int y, int z){
return x+y;
}
int check(std::function<int(int, int, int)> &s, int x, int y){
return s(x, y);
}
int main(){
std::function<int(int, int, int)> s(sum);
std::cout<<check(s, 10, 20)<<std::endl;
// Here a datatype of std::function is define and passed to check,
// which returns int and takes
// three argument int, int, int types
}
To Create a std::function with template example:
template<class E>
bool h (const E& par1){
std::cout<<"This is correct";
return true;
}
template<class E>
E z(std::function<bool(const E&)> F){
}
int main(){
std::function < bool(const int&)> v(h<int>);
std::cout<<v(10);
}
Comments
Post a Comment