boost function_traits
2884 단어 boost 원본 코드 분석
template
struct function_traits
{
static const std::size_t arity = see-below;
typedef see-below result_type;
typedef see-below argN_type;
};
function_traits 클래스 템플릿은 다음 조건이 충족될 때만 컴파일됩니다.· 컴파일러 지원 클래스 템플릿 편향화
· 템플릿 매개 변수 F는 함수 유형입니다. 함수 유형과 함수 포인터 유형은 같지 않습니다.
프롬프트
function_traits는 함수 바늘 형식이나 클래스 구성원 함수 형식이 아닌 R(), R(A1), R(A1,...etc.) 같은 C++ 함수 형식에만 적용됩니다.remove_pointer는 함수 포인터 형식을 상응하는 함수 형식으로 변환할 수 있습니다.
Table 1.19.Function Traits 구성원 함수
Member
Description
function_traits
함수 F 매개 변수의 수를 나타내는 성형 상수 표현식.
function_traits
함수 F의 반환값 유형
function_traits
함수 F의 N번째 매개변수 유형, 여기서 1<=N<=arity
Table 1.20.예.
Expression
Result
function_traits
값이 0인 성형 상수 표현식
function_traits
값이 1인 성형 상수 표현식
function_traits
값이 4인 성형 상수 표현식
function_traits
void 형식.
function_traits
long 유형
function_traits
int 형식
function_traits
void* 유형
function_traits
컴파일 오류, 네 번째 파라미터만 있기 때문에 다섯 번째 파라미터는 존재하지 않습니다
function_traits
컴파일 오류, 매개 변수 형식은 함수 포인터 형식이지 함수 형식이 아닙니다
:
template
struct function_traits_helper;
template
struct function_traits_helper
{
BOOST_STATIC_CONSTANT(unsigned, arity = 0);
typedef R result_type;
};
template
struct function_traits_helper
{
BOOST_STATIC_CONSTANT(unsigned, arity = 1);
typedef R result_type;
typedef T1 arg1_type;
typedef T1 argument_type;
};
template
struct function_traits_helper
{
BOOST_STATIC_CONSTANT(unsigned, arity = 2);
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T1 first_argument_type;
typedef T2 second_argument_type;
};
template
struct function_traits_helper
{
BOOST_STATIC_CONSTANT(unsigned, arity = 3);
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
};
template
struct function_traits : public function_traits_helper::type>
{
};