본문 바로가기
VisualStudio.C++.C#/코딩팁,함수활용,단편

std::function<R(Args...)>::target

by i.got.it 2020. 9. 8.

 

 

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 : 

 

std::function<r(args...)>::target - cppreference.com</r(args...)>

template< class T > T* target() noexcept; (1) (since C++11) template< class T > const T* target() const noexcept; (2) (since C++11) Returns a pointer to the stored callable function target. [edit] Parameters (none) [edit] Return value A pointer to the stor

en.cppreference.com

 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5