SlideShare a Scribd company logo
Effective Modern C++ Study
C++ Korea
C++ Korea
Effective Modern C++ Study
Item 1 – 3
Item 1 : Understand template type deduction.
Item 2 : Understand auto type deduction.
Item 3 : Understand decltype.
Item 1 : Understand template type
deduction.
Speaker : 정은식
Effective Modern C++ Study
C++ Korea
Deducing Types
C++ 11에서의 auto는 template 기반으로 한다.
떄문에 템플릿에 적용할 떄보다 덜 직관적으로
보인다
템플릿에는 추론 방법이 3가지가 있다.
3
Effective Modern C++ Study
C++ Korea
Deducing Types
컴파일을 하는 동안 컴파일러는 T및 paramType
두 타입을 추론하기 위해 expr 을 사용합니다.
4
Effective Modern C++ Study
C++ Korea
Case 1: ParamType 이 참조, 포인터인 경우
Case 2: ParamType 가 Universal Reference 경우
Case 3: ParamType 가 참조 또는 포인터가
아닐떄
5
Effective Modern C++ Study
C++ Korea
Case 1
ParamType 이 참조거나 포인터인 경우
1)expr 타입이 참조 타입일떄 참조 부분은
무시됩니다.
2)expr 타입과 매치한 후 paramtype으로 T를
결정합니다
6
Effective Modern C++ Study
C++ Korea
Case 1
void f(T& param); // param is a reference
int x = 27;
const int cx = x;
const int& rx = x;
F(x); // param int&
F(cx); //param's type is const int&
F(rx); //param's type is const int&
7
Effective Modern C++ Study
C++ Korea
Case 1
template<typename T>
void f(T* param);
int x = 27;
const int *px = &x
f(&x); // param's type is int*
f(px); //param's type is const int*
8
Effective Modern C++ Study
C++ Korea
Case 2:
ParamType 가 Universal Reference 경우
1.If expr is an lvalue
1) T와 paramtype은 lvalue 의해 추론.
2) 비록 paramtype이 rvalue 선언되어있어도 참조lvalue 로 참조
2.expr이 rvalue 일떄 case 1가 동일하게 적용
9
Effective Modern C++ Study
C++ Korea
Case 2:
void f(T&& param);
int x = 27;
const int cx = x;
const int& rx = x;
F(x); F(cx);
F(rx); F(27);
10
Effective Modern C++ Study
C++ Korea
Case 3:
Case 3: ParamType 가 참조,포인터가 아닐떄
expr이 reference ,const,volatile 다 무시됩니다.
11
Effective Modern C++ Study
C++ Korea
Case 3:
void f(T param);
int x = 27;
const int cx = x;
const int& rx = x;
f(x); // T's and param's types are both int
f(cx); // T's and param's types are both int
f(rx); // T's and param's types are both int
12
Effective Modern C++ Study
C++ Korea
정리
템플릿 타입 추론을 하는동안. 레퍼런스 타입의
인수들은 레퍼런스가 아닌 타입으로 취급
유니버셜 레버런스에 대한 타입 추론을 할떄 Lvalue
인수들은 특별한 취급을 받게됨
템플릿 타입 추론을 하는동안 포인터를 사용하는
인수들은 초기화할떄 레퍼런스 타입을 사용하지 않으면
포인터 붕괴가 일어남
13

More Related Content

What's hot

[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
Seok-joon Yun
 
[C++ Korea] Effective Modern C++ Study, Item 1 - 3
[C++ Korea] Effective Modern C++ Study, Item 1 - 3[C++ Korea] Effective Modern C++ Study, Item 1 - 3
[C++ Korea] Effective Modern C++ Study, Item 1 - 3
Chris Ohk
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
Seok-joon Yun
 
[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 studySeok-joon Yun
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...Seok-joon Yun
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
Seok-joon Yun
 
Pure Function and Rx
Pure Function and RxPure Function and Rx
Pure Function and Rx
Hyungho Ko
 
Pure Function and Honest Design
Pure Function and Honest DesignPure Function and Honest Design
Pure Function and Honest Design
Hyungho Ko
 
C++11
C++11C++11
C++11
Yubin Lim
 
Modern effective cpp 항목1
Modern effective cpp 항목1Modern effective cpp 항목1
Modern effective cpp 항목1
Paul Myeongchan Kim
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Seok-joon Yun
 
Ch07
Ch07Ch07
Ch07
Hankyo
 
[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1
지환 김
 
HI-ARC 정기모임 #7 BFS
HI-ARC 정기모임 #7 BFSHI-ARC 정기모임 #7 BFS
HI-ARC 정기모임 #7 BFS
Jae-yeol Lee
 
객체지향 정리. Part1
객체지향 정리. Part1객체지향 정리. Part1
객체지향 정리. Part1
kim HYUNG JIN
 
UNIST Pinocchio - Processing Lecture 1
UNIST Pinocchio - Processing Lecture 1UNIST Pinocchio - Processing Lecture 1
UNIST Pinocchio - Processing Lecture 1
송현 김
 
Ch05
Ch05Ch05
Ch05
Hankyo
 
C++ Advanced 강의 3주차
C++ Advanced 강의 3주차C++ Advanced 강의 3주차
C++ Advanced 강의 3주차
HyunJoon Park
 
Template at c++
Template at c++Template at c++
Template at c++
Lusain Kim
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
MinGeun Park
 

What's hot (20)

[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
 
[C++ Korea] Effective Modern C++ Study, Item 1 - 3
[C++ Korea] Effective Modern C++ Study, Item 1 - 3[C++ Korea] Effective Modern C++ Study, Item 1 - 3
[C++ Korea] Effective Modern C++ Study, Item 1 - 3
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
 
[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
 
Pure Function and Rx
Pure Function and RxPure Function and Rx
Pure Function and Rx
 
Pure Function and Honest Design
Pure Function and Honest DesignPure Function and Honest Design
Pure Function and Honest Design
 
C++11
C++11C++11
C++11
 
Modern effective cpp 항목1
Modern effective cpp 항목1Modern effective cpp 항목1
Modern effective cpp 항목1
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
 
Ch07
Ch07Ch07
Ch07
 
[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1[Effective Modern C++] Chapter1 - item1
[Effective Modern C++] Chapter1 - item1
 
HI-ARC 정기모임 #7 BFS
HI-ARC 정기모임 #7 BFSHI-ARC 정기모임 #7 BFS
HI-ARC 정기모임 #7 BFS
 
객체지향 정리. Part1
객체지향 정리. Part1객체지향 정리. Part1
객체지향 정리. Part1
 
UNIST Pinocchio - Processing Lecture 1
UNIST Pinocchio - Processing Lecture 1UNIST Pinocchio - Processing Lecture 1
UNIST Pinocchio - Processing Lecture 1
 
Ch05
Ch05Ch05
Ch05
 
C++ Advanced 강의 3주차
C++ Advanced 강의 3주차C++ Advanced 강의 3주차
C++ Advanced 강의 3주차
 
Template at c++
Template at c++Template at c++
Template at c++
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 

Viewers also liked

[C++ Korea] Effective Modern C++ Study item 31-33
[C++ Korea] Effective Modern C++ Study item 31-33[C++ Korea] Effective Modern C++ Study item 31-33
[C++ Korea] Effective Modern C++ Study item 31-33
Seok-joon Yun
 
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
Seok-joon Yun
 
Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본
Dong Chan Shin
 
Effective C++ 정리 chapter 3
Effective C++ 정리 chapter 3Effective C++ 정리 chapter 3
Effective C++ 정리 chapter 3
연우 김
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
Chris Ohk
 
Gpg study5.5
Gpg study5.5Gpg study5.5
Gpg study5.5
연우 김
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 

Viewers also liked (7)

[C++ Korea] Effective Modern C++ Study item 31-33
[C++ Korea] Effective Modern C++ Study item 31-33[C++ Korea] Effective Modern C++ Study item 31-33
[C++ Korea] Effective Modern C++ Study item 31-33
 
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
[C++ Korea] Effective Modern C++ Sinchon Study Item 37-39
 
Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본
 
Effective C++ 정리 chapter 3
Effective C++ 정리 chapter 3Effective C++ 정리 chapter 3
Effective C++ 정리 chapter 3
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
 
Gpg study5.5
Gpg study5.5Gpg study5.5
Gpg study5.5
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 

[C++ korea] effective modern c++ study item 1정은식

  • 1. Effective Modern C++ Study C++ Korea C++ Korea Effective Modern C++ Study Item 1 – 3 Item 1 : Understand template type deduction. Item 2 : Understand auto type deduction. Item 3 : Understand decltype.
  • 2. Item 1 : Understand template type deduction. Speaker : 정은식
  • 3. Effective Modern C++ Study C++ Korea Deducing Types C++ 11에서의 auto는 template 기반으로 한다. 떄문에 템플릿에 적용할 떄보다 덜 직관적으로 보인다 템플릿에는 추론 방법이 3가지가 있다. 3
  • 4. Effective Modern C++ Study C++ Korea Deducing Types 컴파일을 하는 동안 컴파일러는 T및 paramType 두 타입을 추론하기 위해 expr 을 사용합니다. 4
  • 5. Effective Modern C++ Study C++ Korea Case 1: ParamType 이 참조, 포인터인 경우 Case 2: ParamType 가 Universal Reference 경우 Case 3: ParamType 가 참조 또는 포인터가 아닐떄 5
  • 6. Effective Modern C++ Study C++ Korea Case 1 ParamType 이 참조거나 포인터인 경우 1)expr 타입이 참조 타입일떄 참조 부분은 무시됩니다. 2)expr 타입과 매치한 후 paramtype으로 T를 결정합니다 6
  • 7. Effective Modern C++ Study C++ Korea Case 1 void f(T& param); // param is a reference int x = 27; const int cx = x; const int& rx = x; F(x); // param int& F(cx); //param's type is const int& F(rx); //param's type is const int& 7
  • 8. Effective Modern C++ Study C++ Korea Case 1 template<typename T> void f(T* param); int x = 27; const int *px = &x f(&x); // param's type is int* f(px); //param's type is const int* 8
  • 9. Effective Modern C++ Study C++ Korea Case 2: ParamType 가 Universal Reference 경우 1.If expr is an lvalue 1) T와 paramtype은 lvalue 의해 추론. 2) 비록 paramtype이 rvalue 선언되어있어도 참조lvalue 로 참조 2.expr이 rvalue 일떄 case 1가 동일하게 적용 9
  • 10. Effective Modern C++ Study C++ Korea Case 2: void f(T&& param); int x = 27; const int cx = x; const int& rx = x; F(x); F(cx); F(rx); F(27); 10
  • 11. Effective Modern C++ Study C++ Korea Case 3: Case 3: ParamType 가 참조,포인터가 아닐떄 expr이 reference ,const,volatile 다 무시됩니다. 11
  • 12. Effective Modern C++ Study C++ Korea Case 3: void f(T param); int x = 27; const int cx = x; const int& rx = x; f(x); // T's and param's types are both int f(cx); // T's and param's types are both int f(rx); // T's and param's types are both int 12
  • 13. Effective Modern C++ Study C++ Korea 정리 템플릿 타입 추론을 하는동안. 레퍼런스 타입의 인수들은 레퍼런스가 아닌 타입으로 취급 유니버셜 레버런스에 대한 타입 추론을 할떄 Lvalue 인수들은 특별한 취급을 받게됨 템플릿 타입 추론을 하는동안 포인터를 사용하는 인수들은 초기화할떄 레퍼런스 타입을 사용하지 않으면 포인터 붕괴가 일어남 13