Your SlideShare is downloading. ×
0
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Cpp 0x kimRyungee
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Cpp 0x kimRyungee

1,044

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,044
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. C++ 0x 달려 BOA요~ 아.꿈.사 비밀 모임 발표 : 김연기
  • 2. 발표자 는 뉴규? 김연기 아.꿈.사 오후반 스터디 그룹 장소 예약 담당 (Pattern Oriented Software Architecture 2) 2008. 10 ~ Microsoft Visual C++ MVP 유콘시스템 Sw개발팀 지상관제 장비 SW 개발 잉카 인터넷 보안개발팀 업데이트 모듈 개발. http://twitter.com/scor7910 http://scor7910.tistory.com
  • 3. 차례• 새롭게 추가 된 것들. – Lambda – R-Value Reference – auto, decltype, constexpr – Smart Pointer• 참고자료.• Q&A
  • 4. Lambda• 명명되지 않은(Unnamed) 함수 객체.
  • 5. Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Introducer
  • 6. Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Parameter declaration
  • 7. Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Compound Statement
  • 8. Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Return Type
  • 9. Lambda –사용-int main() {vector<int> v;for (int i = 0; i < 10; ++i){ v.push_back(i);}for_each(v.begin(), v.end(), [](int n) { cout << n << " "; }); cout << endl;}
  • 10. Lambda –함수객체-struct LambdaFunctor { void operator()(int n) const { cout << n << " "; }};…….for_each(v.begin(), v.end(), LambdaFunctor() );
  • 11. Lambda –리턴-• []()->리턴 타입{…}transform(v.begin(), v.end(), front_inserter(d), [](intn) -> double { if (n % 2 == 0) { return n * n * n; } else { return n / 2.0; }});
  • 12. Lambda –캡쳐-• 상위 스코프({…})의 변수를 람다 구현내부 에서 사용할 수 있다.• [변수1, 변수2] : 변수1, 변수2 캡쳐• [&변수1, &변수2] : 변수1, 변수2 참조캡쳐• [&] : 상위 스코프의 변수를 참조 캡쳐.• [=] : 상위 스코프의 변수를 값 캡쳐.
  • 13. Lambda –캡쳐-int x = 4;int y = 5;cout << "Input: ";cin >> x >> y;v.erase(remove_if(v.begin(), v.end(), [x, y](int n){ return x < n && n < y; }), v.end());int x = 4;int y = 5;for_each(v.begin(), v.end(), [=](int& r) mutable {//값을 캡쳐하면 x,y는 const로 들어오지만 mutable 키워드로//캡쳐된 변수를 변경가능한 변수로 만들어줌. const int old = r; r *= x * y; x = y; y = old; });
  • 14. Lambda –캡쳐-int x = 4;int y = 5;cout << "Input: ";cin >> x >> y;v.erase(remove_if(v.begin(), v.end(), [&x, &y](int n){ return x < n && n < y; }), v.end());int x = 4;int y = 5;for_each(v.begin(), v.end(), [&](int& r) { const int old = r; r *= x * y; x = y; y = old; });
  • 15. R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++);
  • 16. R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++); a 10 b 13 res b++ ++a (++a + b++)
  • 17. R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++); a 10 b 13 res b++ ++a (++a + b++)
  • 18. R-Value Referencedouble& rd1 = 2.0;const double& rd2 = 2.0;double&& rd3 = 2.0;rd2 += 1;rd3 +=3;
  • 19. R-Value Referencedouble& rd1 = 2.0; ERROR!!const double& rd2 = 2.0;double&& rd3 = 2.0;rd2 += 1; ERROR!!rd3 +=3;
  • 20. R-Value Reference –Move-class SomeThing int main(){ { public: SomeThing S1; SomeThing() {} S1.data_.a = 0; SomeThing(SomeThing& s) S1.data_.b = 10; { strcpy(S1.data_.c, "KimRyungee"); memcpy(&data_, &s.data_, sizeof(A)); SomeThing S2(S1); } SomeThing&& SomeThing(SomeThing&& s) S3(forward<SomeThing&&>(S1)); { SomeThing& S4 = S2; data_ = move(s.data_); return 0; } } ~SomeThing() { } A data_;};
  • 21. autofor (vector<int>::const_iterator itr = myvec.begin(); itr != myvec.end(); ++itr)for (auto itr = myvec.begin(); itr != myvec.end(); ++itr)
  • 22. decltypeconst int&& foo();int i;struct A { double x; };const A* a = new A();decltype(foo()) x1 = i; // x1 타입은 const int&&decltype(i) x2; // x2 타입은 intdecltype(a->x) x3; // x3 타입은 doubledecltype((a->x)) x4 = x3; // x4 타입은 double&
  • 23. constexprconstexptr GetBufferSize();TCHAR buffer[GetBufferSize ()+ 12];
  • 24. Smart Pointer –auto_ptr-class LessPtr int main(){ {public: vector< auto_ptr<int> > arrInt; bool operator () vector< auto_ptr<int> >::iterator ( auto_ptr<int> ptr1, pos = arrInt.begin(); auto_ptr<int> ptr2) const { /*생략*/ return *(ptr1.get()) > sort(arrInt.begin(), arrInt.end(), *(ptr2.get()) ? LessPtr()); true : false; pos = arrInt.begin(); } for(; pos != arrInt.end(); ++pos)}; { cout<<" "<<(*pos).get()<<" "; } return 0; }
  • 25. Smart Pointer –auto_ptr-class LessPtr int main(){ {public: vector< auto_ptr<int> > arrInt; bool operator () vector< auto_ptr<int> >::iterator ( auto_ptr<int> ptr1, pos = arrInt.begin(); auto_ptr<int> ptr2) const { /*생략*/ return *(ptr1.get()) > sort(arrInt.begin(), arrInt.end(), *(ptr2.get()) ? LessPtr()); true : false; pos = arrInt.begin(); } for(; pos != arrInt.end(); ++pos)}; { cout<<" "<<(*pos).get()<<" "; } return 0; }
  • 26. Smart Pointer –auto_ptr-template<class _Other>_Myt& operator=(auto_ptr<_Other>& _Right) _THROW0(){ // assign compatible _Right (assume pointer) reset(_Right.release()); return (*this);}
  • 27. Smart Pointer –shared_ptr-class LessSharedPtr int main(){ {public: vector< shared_ptr<int> > arrInt; bool operator () vector< shared_ptr<int> >::iterator ( shared_ptr<int> ptr1, pos = arrInt.begin(); shared_ptr<int> ptr2) const /*생략*/ { sort(arrInt.begin(), arrInt.end(), return *(ptr1.get()) > LessSharedPtr()); *(ptr2.get()) ? pos = arrInt.begin(); true : false; for(; pos != arrInt.end(); ++pos) } {}; cout<<" "<<*((*pos).get()) <<" "; } return 0; }
  • 28. Smart Pointer -weak_ptr-• shared_ptr의 리소스를 카운팅을 증가하지 않은채 가지고 있는 포인터.• 레퍼런스 카운팅에 영향을 주지 않는다.• Shared_ptr 객체를 생성후 사용해야 한다.
  • 29. Smart Pointer -unique_ptr-• 할당된 객체를 공유하지 않는 스마트 포인 터.• Move 생성자/연산자만 사용할 수 있다.
  • 30. 참고자료• http://msdn.microsoft.com/en- us/library/cscc687y.aspx• http://herbsutter.com• http://en.wikipedia.org/• http://www.open- std.org/JTC1/SC22/WG21/• Effective STL

×