SlideShare a Scribd company logo
1 of 24
Download to read offline
Effective Modern C++ Study
C++ Korea
Effective Modern C++ Study
C++ Korea3
widget.h
string vector gadget.h
Effective Modern C++ Study
C++ Korea4
widget.cpp
string vector gadget.h widget.h
Effective Modern C++ Study
C++ Korea5
조금 더 나은 모양
Effective Modern C++ Study
C++ Korea7
Effective Modern C++ Study
C++ Korea8
header에서는 정의만 할 수 있도록 할 것.
???
Effective Modern C++ Study
C++ Korea9
Effective Modern C++ Study
C++ Korea10
Effective Modern C++ Study
C++ Korea
template<typename T>
void func(T&& param);
 T가 아닌 param의 type
Effective Modern C++ Study
C++ Korea
template<typename T>
void func(T&& param);
Widget widgetFactory(); // function returning rvalue
Widget w; // a variable (an lvalue)
func(w); // call func with lvalue; T deduced
// to be Widget&
func(widgetFactory()); // call func with rvalue; T deduced
// to be Widget
Effective Modern C++ Study
C++ Korea
int x;
auto& & rx = x; // error! can't declare reference to reference
Effective Modern C++ Study
C++ Korea
void func(Widget& && param);
 void func(Widget& param);
Effective Modern C++ Study
C++ Korea
template<typename T>
void f(T&& fParam)
{
someFunc(std::forward<T>(fParam)); // forward fParam to
} // someFunc
template<typename T>
T&& forward(typename remove_reference<T>::type& param)
{
return static_cast<T&&>(param);
}
Effective Modern C++ Study
C++ Korea
Widget& && forward(typename
remove_reference<Widget&>::type& param)
{
return static_cast<Widget& &&>(param);
}
Widget& && forward(Widget& param)
{
return static_cast<Widget& &&>(param);
}
Widget& forward(Widget& param)
{
return static_cast<Widget&>(param);
}
Effective Modern C++ Study
C++ Korea
Widget&& forward(typename
remove_reference<Widget>::type& param)
{
return static_cast<Widget&&>(param);
}
Widget&& forward(Widget& param)
{
return static_cast<Widget&&>(param);
}
Effective Modern C++ Study
C++ Korea
template<typename T>
T&& forward(remove_reference_t<T>& param)
{
return static_cast<T&&>(param);
}
Effective Modern C++ Study
C++ Korea
template<typename T>
void func(T&& param);
Widget widgetFactory(); // function returning rvalue
Widget w; // a variable (an lvalue)
func(w); // call func with lvalue; T deduced
// to be Widget&
func(widgetFactory()); // call func with rvalue; T deduced
// to be Widget
Effective Modern C++ Study
C++ Korea
auto&& w1 = w;
Widget& && w1 = w;
auto&& w2 = widgetFactory();
Widget&& w2 = widgetFactory();
Effective Modern C++ Study
C++ Korea
template<typename T>
class Widget {
public:
typedef T&& RvalueRefToT;
};
Widget<int&> w;
typedef int& && RvalueRefToT;
typedef int& RvalueRefToT;
Effective Modern C++ Study
C++ Korea
Effective Modern C++ Study
C++ Korea

More Related Content

More from Seok-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
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1Seok-joon Yun
 
[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX LockSeok-joon Yun
 

More from Seok-joon Yun (20)

아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지아파트 시세,어쩌다 머신러닝까지
아파트 시세,어쩌다 머신러닝까지
 
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
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
 
[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock
 

[C++ Korea] Effective Modern C++ Study item 22,28

  • 1. Effective Modern C++ Study C++ Korea
  • 2.
  • 3. Effective Modern C++ Study C++ Korea3 widget.h string vector gadget.h
  • 4. Effective Modern C++ Study C++ Korea4 widget.cpp string vector gadget.h widget.h
  • 5. Effective Modern C++ Study C++ Korea5 조금 더 나은 모양
  • 6.
  • 7. Effective Modern C++ Study C++ Korea7
  • 8. Effective Modern C++ Study C++ Korea8 header에서는 정의만 할 수 있도록 할 것. ???
  • 9. Effective Modern C++ Study C++ Korea9
  • 10. Effective Modern C++ Study C++ Korea10
  • 11.
  • 12. Effective Modern C++ Study C++ Korea template<typename T> void func(T&& param);  T가 아닌 param의 type
  • 13. Effective Modern C++ Study C++ Korea template<typename T> void func(T&& param); Widget widgetFactory(); // function returning rvalue Widget w; // a variable (an lvalue) func(w); // call func with lvalue; T deduced // to be Widget& func(widgetFactory()); // call func with rvalue; T deduced // to be Widget
  • 14. Effective Modern C++ Study C++ Korea int x; auto& & rx = x; // error! can't declare reference to reference
  • 15. Effective Modern C++ Study C++ Korea void func(Widget& && param);  void func(Widget& param);
  • 16. Effective Modern C++ Study C++ Korea template<typename T> void f(T&& fParam) { someFunc(std::forward<T>(fParam)); // forward fParam to } // someFunc template<typename T> T&& forward(typename remove_reference<T>::type& param) { return static_cast<T&&>(param); }
  • 17. Effective Modern C++ Study C++ Korea Widget& && forward(typename remove_reference<Widget&>::type& param) { return static_cast<Widget& &&>(param); } Widget& && forward(Widget& param) { return static_cast<Widget& &&>(param); } Widget& forward(Widget& param) { return static_cast<Widget&>(param); }
  • 18. Effective Modern C++ Study C++ Korea Widget&& forward(typename remove_reference<Widget>::type& param) { return static_cast<Widget&&>(param); } Widget&& forward(Widget& param) { return static_cast<Widget&&>(param); }
  • 19. Effective Modern C++ Study C++ Korea template<typename T> T&& forward(remove_reference_t<T>& param) { return static_cast<T&&>(param); }
  • 20. Effective Modern C++ Study C++ Korea template<typename T> void func(T&& param); Widget widgetFactory(); // function returning rvalue Widget w; // a variable (an lvalue) func(w); // call func with lvalue; T deduced // to be Widget& func(widgetFactory()); // call func with rvalue; T deduced // to be Widget
  • 21. Effective Modern C++ Study C++ Korea auto&& w1 = w; Widget& && w1 = w; auto&& w2 = widgetFactory(); Widget&& w2 = widgetFactory();
  • 22. Effective Modern C++ Study C++ Korea template<typename T> class Widget { public: typedef T&& RvalueRefToT; }; Widget<int&> w; typedef int& && RvalueRefToT; typedef int& RvalueRefToT;
  • 23. Effective Modern C++ Study C++ Korea
  • 24. Effective Modern C++ Study C++ Korea