std::function<R(Args...)>::target
Returns a pointer to the stored callable function target.
Return value
A pointer to the stored function if target_type() == typeid(T), otherwise a null pointer.
#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));
}
/////////////////
test function: it is plus
test function: it is minus
test function: it is the function f
test function: it is the function g
from :
'VisualStudio.C++.C# > 코딩팁,함수활용,단편' 카테고리의 다른 글
MFC. pch.h precompiled header 사용하지 않음 설정 (0) | 2020.09.13 |
---|---|
Visual C++ 2019 . WebSocket 구현 골격. cpprestsdk 기반. (0) | 2020.09.09 |
Fixed width integer types C99표준. stdint.h 에 정의 있음. uint8_t, uint64_t 등. (0) | 2020.09.07 |
win API . FindWindow , FindWindowEx (0) | 2020.09.05 |
MFC.대화상자. x버튼 그레이처리 (1) | 2020.08.31 |
댓글