[정리] Template Type Deduction


[정리] Template Type Deduction

Type을 조사하는 방법 1. C++ 표준의 typeid() 연산자 사용 . const, volatile, reference를 조사할 수 없다. 2. boost의 type_index 라이브러리 사용 . const. volatile, reference를 모두 조사할 수 있다. C++표준 RTTI를 사용한 타입 조사 결과는 int, int, double, double로 조사된다. 이유는 typeid(T)는 const를 조사할 수 없기 때문이다. boost::type_index 라이브러리 사용한 타입 조사 결과는 int, int const, double, double const로 조사된다. boost 라이브러리는 const를 조사할 수 있다. Type Deduction이란, 컴파일러가 함수 인자를 통해서 T의 타입을 결정하는 과정 c의 정확한 타입은 const int 이므로 에러 발생이 예상된다. r의 정확한 타입은 int& 이므로 T가 int&로 결정되게 된다면, sum()을 실행하고나...


#boost #volatile #typeid #type_index #type #template #reference #detection #const #템플릿

원문링크 : [정리] Template Type Deduction