SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
Effective Modern C++ Study
C++ Korea
발표자 : 윤석준
Effective Modern C++ Study
C++ Korea3
auto GL = [](auto ) { return F( ); };
class CompilerGeneratedClosureClass
{
public:
template <typename T>
auto operator() (T X) const
{
return F(X);
}
};
Compiler는 operator() 를 가진 template closure class로 구현
Effective Modern C++ Study
C++ Korea4
auto GL = [](auto&& ) { return F(std::forward<???>(X)); };
만약 F(X)가 R-Value와 L-Value를 다르게 취급해야 한다면 ???
Perfect-forward(X)를 전달해야 한다.
1. X가 Universal Reference 여야 한다.
2. std::forward를 거쳐서 F( ) 에 전달되어야 한다.
auto GL = [](auto ) { return F( ); };
아놔 근데… ??? 에 뭘 적어야 하나 ???
template closure class 에는 T가 있지만, Lambda에는… @#$%?
template <typename T>
auto operator() (T X) const
{
return F(X);
}
Effective Modern C++ Study
C++ Korea5
Universal Reference
L-Value
R-Value
L-Value Reference
R-Value Reference
decltype(x)
L-Value
R-Value
L-Value Reference
R-Value Reference
std::forward<T>
L-Value Reference
Non-Reference
L-Value
R-Value
Effective Modern C++ Study
C++ Korea6
template<typename T>
T&& forward(remove_reference_t<T>& param)
{
return static_cast<T&&>(param);
}
Instantiation of std::forward when T is Widget
Widget&& forward(Widget& param)
{
return static_cast<Widget&&>(param);
}
R-Value 타입의 Widget을 Perfect-forward하기를 바랄 때,
T를 Non-Reference로 하는 규칙 대신에, R-Value Reference로 지정하는 것을 고려해 본다면…
한마디로 T가 Widget이 아니라 Widget&& 일 경우를 한번 보자는 거다.
Effective Modern C++ Study
C++ Korea7
Widget&& && forward(Widget& )
{
return static_cast<Widget&& &&>(param);
}
&& && 가 도대체 뭥미 ? Reference-Collapsing (참조 붕괴) 적용
Widget&& forward(Widget& param)
{
return static_cast<Widget&&>(param);
}
어라 ?
T를 R-Value Reference로 Instantiation 한거랑,
Non-Reference 로 Instantiation 한거랑 같다.
에헤라 디야~ 옳다구나.
Effective Modern C++ Study
C++ Korea8
decltype(x)
L-Value
R-Value
L-Value Reference
R-Value Reference
std::forward<decltype(x)>
Non-Reference
L-Value
R-Value
auto PFL = [](auto&& ) { return F(std::forward<decltype(x)>(X)); };
Effective Modern C++ Study
C++ Korea9
Any number of parameters
auto PFL = [](auto&& ) { return F(std::forward<decltype(X)>(X)); };
auto PFL = [](auto&&… param)
{ return F(std::forward<decltype(param)>((param)…)); };
Effective Modern C++ Study
C++ Korea10
• std::forward<T>(X)에 auto&& 를 넣을 땐 decltype 을 사용하자.
• 즉, std::forward<decltype(X)>(X) 이렇게 쓰라는 거다.
http://devluna.blogspot.kr/2015/03/item-33-stdforward-auto-decltype.html
icysword77@gmail.com

Weitere ähnliche Inhalte

Mehr von Seok-joon Yun

AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterAWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterSeok-joon Yun
 
아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지Seok-joon Yun
 
Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformanceSeok-joon Yun
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07Seok-joon Yun
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06Seok-joon Yun
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05Seok-joon Yun
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04Seok-joon Yun
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03Seok-joon Yun
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02Seok-joon Yun
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01Seok-joon Yun
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptSeok-joon Yun
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsSeok-joon Yun
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++Seok-joon Yun
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2Seok-joon Yun
 
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstatSeok-joon Yun
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4Seok-joon Yun
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료Seok-joon Yun
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3Seok-joon Yun
 
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2Seok-joon Yun
 

Mehr von Seok-joon Yun (20)

Eks.introduce
Eks.introduceEks.introduce
Eks.introduce
 
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image ConverterAWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
 
아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지
 
Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, Performance
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threads
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2
 
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
 
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
 

[C++ Korea] Effective Modern C++ Study item 33 Use dectype on auto&& parameters to std::forward them +윤석준

  • 1. Effective Modern C++ Study C++ Korea 발표자 : 윤석준
  • 2.
  • 3. Effective Modern C++ Study C++ Korea3 auto GL = [](auto ) { return F( ); }; class CompilerGeneratedClosureClass { public: template <typename T> auto operator() (T X) const { return F(X); } }; Compiler는 operator() 를 가진 template closure class로 구현
  • 4. Effective Modern C++ Study C++ Korea4 auto GL = [](auto&& ) { return F(std::forward<???>(X)); }; 만약 F(X)가 R-Value와 L-Value를 다르게 취급해야 한다면 ??? Perfect-forward(X)를 전달해야 한다. 1. X가 Universal Reference 여야 한다. 2. std::forward를 거쳐서 F( ) 에 전달되어야 한다. auto GL = [](auto ) { return F( ); }; 아놔 근데… ??? 에 뭘 적어야 하나 ??? template closure class 에는 T가 있지만, Lambda에는… @#$%? template <typename T> auto operator() (T X) const { return F(X); }
  • 5. Effective Modern C++ Study C++ Korea5 Universal Reference L-Value R-Value L-Value Reference R-Value Reference decltype(x) L-Value R-Value L-Value Reference R-Value Reference std::forward<T> L-Value Reference Non-Reference L-Value R-Value
  • 6. Effective Modern C++ Study C++ Korea6 template<typename T> T&& forward(remove_reference_t<T>& param) { return static_cast<T&&>(param); } Instantiation of std::forward when T is Widget Widget&& forward(Widget& param) { return static_cast<Widget&&>(param); } R-Value 타입의 Widget을 Perfect-forward하기를 바랄 때, T를 Non-Reference로 하는 규칙 대신에, R-Value Reference로 지정하는 것을 고려해 본다면… 한마디로 T가 Widget이 아니라 Widget&& 일 경우를 한번 보자는 거다.
  • 7. Effective Modern C++ Study C++ Korea7 Widget&& && forward(Widget& ) { return static_cast<Widget&& &&>(param); } && && 가 도대체 뭥미 ? Reference-Collapsing (참조 붕괴) 적용 Widget&& forward(Widget& param) { return static_cast<Widget&&>(param); } 어라 ? T를 R-Value Reference로 Instantiation 한거랑, Non-Reference 로 Instantiation 한거랑 같다. 에헤라 디야~ 옳다구나.
  • 8. Effective Modern C++ Study C++ Korea8 decltype(x) L-Value R-Value L-Value Reference R-Value Reference std::forward<decltype(x)> Non-Reference L-Value R-Value auto PFL = [](auto&& ) { return F(std::forward<decltype(x)>(X)); };
  • 9. Effective Modern C++ Study C++ Korea9 Any number of parameters auto PFL = [](auto&& ) { return F(std::forward<decltype(X)>(X)); }; auto PFL = [](auto&&… param) { return F(std::forward<decltype(param)>((param)…)); };
  • 10. Effective Modern C++ Study C++ Korea10 • std::forward<T>(X)에 auto&& 를 넣을 땐 decltype 을 사용하자. • 즉, std::forward<decltype(X)>(X) 이렇게 쓰라는 거다.