Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

689 views

Published on

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

Published in: Software
  • If you want to download or read this book, copy link or url below in the New tab ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • If you want to download or read this book, copy link or url below in the New tab ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { https://urlzs.com/UABbn } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • If you want to download or read this book, copy link or url below in the New tab ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { https://urlzs.com/UABbn } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • -- DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT -- ......................................................................................................................... ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... (Unlimited)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

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

  1. 1. Effective Modern C++ Study C++ Korea 발표자 : 윤석준
  2. 2. 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로 구현
  3. 3. 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); }
  4. 4. 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
  5. 5. 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&& 일 경우를 한번 보자는 거다.
  6. 6. 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 한거랑 같다. 에헤라 디야~ 옳다구나.
  7. 7. 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)); };
  8. 8. 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)…)); };
  9. 9. Effective Modern C++ Study C++ Korea10 • std::forward<T>(X)에 auto&& 를 넣을 땐 decltype 을 사용하자. • 즉, std::forward<decltype(X)>(X) 이렇게 쓰라는 거다.
  10. 10. http://devluna.blogspot.kr/2015/03/item-33-stdforward-auto-decltype.html icysword77@gmail.com

×