SlideShare ist ein Scribd-Unternehmen logo
1 von 13
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

Weitere ähnliche Inhalte

Was ist angesagt?

[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
Seok-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
 

Was ist angesagt? (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
 

Andere mochten auch

Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
흥배 최
 

Andere mochten auch (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 핵심
 

Kürzlich hochgeladen

Kürzlich hochgeladen (8)

공학 관점에서 바라본 JMP 머신러닝 최적화
공학 관점에서 바라본 JMP 머신러닝 최적화공학 관점에서 바라본 JMP 머신러닝 최적화
공학 관점에서 바라본 JMP 머신러닝 최적화
 
JMP 기능의 확장 및 내재화의 핵심 JMP-Python 소개
JMP 기능의 확장 및 내재화의 핵심 JMP-Python 소개JMP 기능의 확장 및 내재화의 핵심 JMP-Python 소개
JMP 기능의 확장 및 내재화의 핵심 JMP-Python 소개
 
JMP를 활용한 가속열화 분석 사례
JMP를 활용한 가속열화 분석 사례JMP를 활용한 가속열화 분석 사례
JMP를 활용한 가속열화 분석 사례
 
데이터 분석 문제 해결을 위한 나의 JMP 활용법
데이터 분석 문제 해결을 위한 나의 JMP 활용법데이터 분석 문제 해결을 위한 나의 JMP 활용법
데이터 분석 문제 해결을 위한 나의 JMP 활용법
 
JMP를 활용한 전자/반도체 산업 Yield Enhancement Methodology
JMP를 활용한 전자/반도체 산업 Yield Enhancement MethodologyJMP를 활용한 전자/반도체 산업 Yield Enhancement Methodology
JMP를 활용한 전자/반도체 산업 Yield Enhancement Methodology
 
JMP가 걸어온 여정, 새로운 도약 JMP 18!
JMP가 걸어온 여정, 새로운 도약 JMP 18!JMP가 걸어온 여정, 새로운 도약 JMP 18!
JMP가 걸어온 여정, 새로운 도약 JMP 18!
 
(독서광) 인간이 초대한 대형 참사 - 대형 참사가 일어날 때까지 사람들은 무엇을 하고 있었는가?
(독서광) 인간이 초대한 대형 참사 - 대형 참사가 일어날 때까지 사람들은 무엇을 하고 있었는가?(독서광) 인간이 초대한 대형 참사 - 대형 참사가 일어날 때까지 사람들은 무엇을 하고 있었는가?
(독서광) 인간이 초대한 대형 참사 - 대형 참사가 일어날 때까지 사람들은 무엇을 하고 있었는가?
 
실험 설계의 평가 방법: Custom Design을 중심으로 반응인자 최적화 및 Criteria 해석
실험 설계의 평가 방법: Custom Design을 중심으로 반응인자 최적화 및 Criteria 해석실험 설계의 평가 방법: Custom Design을 중심으로 반응인자 최적화 및 Criteria 해석
실험 설계의 평가 방법: Custom Design을 중심으로 반응인자 최적화 및 Criteria 해석
 

[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