Cpp 0x kimRyungee
Upcoming SlideShare
Loading in...5
×
 

Cpp 0x kimRyungee

on

  • 1,219 views

 

Statistics

Views

Total Views
1,219
Views on SlideShare
877
Embed Views
342

Actions

Likes
1
Downloads
0
Comments
0

4 Embeds 342

http://scor7910.tistory.com 317
http://andstudy.com 16
http://www.andstudy.com 7
http://www.hanrss.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Cpp 0x kimRyungee Cpp 0x kimRyungee Presentation Transcript

  • C++ 0x 달려 BOA요~ 아.꿈.사 비밀 모임 발표 : 김연기
  • 발표자 는 뉴규? 김연기 아.꿈.사 오후반 스터디 그룹 장소 예약 담당 (Pattern Oriented Software Architecture 2) 2008. 10 ~ Microsoft Visual C++ MVP 유콘시스템 Sw개발팀 지상관제 장비 SW 개발 잉카 인터넷 보안개발팀 업데이트 모듈 개발. http://twitter.com/scor7910 http://scor7910.tistory.com
  • 차례• 새롭게 추가 된 것들. – Lambda – R-Value Reference – auto, decltype, constexpr – Smart Pointer• 참고자료.• Q&A
  • Lambda• 명명되지 않은(Unnamed) 함수 객체.
  • Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Introducer
  • Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Parameter declaration
  • Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Compound Statement
  • Lambda• 명명되지 않은(Unnamed) 함수 객체. Lambda Return Type
  • 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;}
  • Lambda –함수객체-struct LambdaFunctor { void operator()(int n) const { cout << n << " "; }};…….for_each(v.begin(), v.end(), LambdaFunctor() );
  • Lambda –리턴-• []()->리턴 타입{…}transform(v.begin(), v.end(), front_inserter(d), [](intn) -> double { if (n % 2 == 0) { return n * n * n; } else { return n / 2.0; }});
  • Lambda –캡쳐-• 상위 스코프({…})의 변수를 람다 구현내부 에서 사용할 수 있다.• [변수1, 변수2] : 변수1, 변수2 캡쳐• [&변수1, &변수2] : 변수1, 변수2 참조캡쳐• [&] : 상위 스코프의 변수를 참조 캡쳐.• [=] : 상위 스코프의 변수를 값 캡쳐.
  • 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; });
  • 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; });
  • R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++);
  • R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++); a 10 b 13 res b++ ++a (++a + b++)
  • R-Value Reference• L-Value & R-Value a=10; b =13; res = (++a + b++); a 10 b 13 res b++ ++a (++a + b++)
  • R-Value Referencedouble& rd1 = 2.0;const double& rd2 = 2.0;double&& rd3 = 2.0;rd2 += 1;rd3 +=3;
  • R-Value Referencedouble& rd1 = 2.0; ERROR!!const double& rd2 = 2.0;double&& rd3 = 2.0;rd2 += 1; ERROR!!rd3 +=3;
  • 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_;};
  • autofor (vector<int>::const_iterator itr = myvec.begin(); itr != myvec.end(); ++itr)for (auto itr = myvec.begin(); itr != myvec.end(); ++itr)
  • 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&
  • constexprconstexptr GetBufferSize();TCHAR buffer[GetBufferSize ()+ 12];
  • 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; }
  • 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; }
  • Smart Pointer –auto_ptr-template<class _Other>_Myt& operator=(auto_ptr<_Other>& _Right) _THROW0(){ // assign compatible _Right (assume pointer) reset(_Right.release()); return (*this);}
  • 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; }
  • Smart Pointer -weak_ptr-• shared_ptr의 리소스를 카운팅을 증가하지 않은채 가지고 있는 포인터.• 레퍼런스 카운팅에 영향을 주지 않는다.• Shared_ptr 객체를 생성후 사용해야 한다.
  • Smart Pointer -unique_ptr-• 할당된 객체를 공유하지 않는 스마트 포인 터.• Move 생성자/연산자만 사용할 수 있다.
  • 참고자료• 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