SlideShare a Scribd company logo
1 of 31
Download to read offline
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), [](int
n) -> 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 Reference

double& rd1 = 2.0;
const double& rd2 = 2.0;
double&& rd3 = 2.0;

rd2 += 1;
rd3 +=3;
R-Value Reference

double& 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_;
};
auto

for (vector<int>::const_iterator itr = myvec.begin(); itr !=
                                                myvec.end(); ++itr)




for (auto itr = myvec.begin(); itr != myvec.end(); ++itr)
decltype

const int&& foo();
int i;
struct A { double x; };
const A* a = new A();

decltype(foo()) x1 = i; // x1 타입은 const int&&
decltype(i) x2;         // x2 타입은 int
decltype(a->x) x3;     // x3 타입은 double
decltype((a->x)) x4 = x3; // x4 타입은 double&
constexpr


constexptr 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
Cpp 0x kimRyungee

More Related Content

What's hot

Es2015 Simple Overview
Es2015 Simple OverviewEs2015 Simple Overview
Es2015 Simple OverviewKim Hunmin
 
Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Circulus
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
 
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Isaac Jeon
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기Jongwook Choi
 
자료구조 그래프 보고서
자료구조 그래프 보고서자료구조 그래프 보고서
자료구조 그래프 보고서mil23
 
2013 C++ Study For Students #1
2013 C++ Study For Students #12013 C++ Study For Students #1
2013 C++ Study For Students #1Chris Ohk
 
[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)NAVER D2
 
자료구조 05 최종 보고서
자료구조 05 최종 보고서자료구조 05 최종 보고서
자료구조 05 최종 보고서pkok15
 
Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석용 최
 
#아두이노 초급연수
#아두이노 초급연수#아두이노 초급연수
#아두이노 초급연수gongdigi24
 
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로Oracle Korea
 
이산수학 C1 프로젝트 7
이산수학 C1 프로젝트 7이산수학 C1 프로젝트 7
이산수학 C1 프로젝트 7pkok15
 
Javascript개발자의 눈으로 python 들여다보기
Javascript개발자의 눈으로 python 들여다보기Javascript개발자의 눈으로 python 들여다보기
Javascript개발자의 눈으로 python 들여다보기지수 윤
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2Chris Ohk
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 명신 김
 
13장 연산자 오버로딩
13장 연산자 오버로딩13장 연산자 오버로딩
13장 연산자 오버로딩유석 남
 

What's hot (20)

6 function
6 function6 function
6 function
 
Es2015 Simple Overview
Es2015 Simple OverviewEs2015 Simple Overview
Es2015 Simple Overview
 
W14 chap13
W14 chap13W14 chap13
W14 chap13
 
Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기
 
자료구조 그래프 보고서
자료구조 그래프 보고서자료구조 그래프 보고서
자료구조 그래프 보고서
 
2013 C++ Study For Students #1
2013 C++ Study For Students #12013 C++ Study For Students #1
2013 C++ Study For Students #1
 
[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)
 
자료구조 05 최종 보고서
자료구조 05 최종 보고서자료구조 05 최종 보고서
자료구조 05 최종 보고서
 
Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석
 
강의자료 2
강의자료 2강의자료 2
강의자료 2
 
#아두이노 초급연수
#아두이노 초급연수#아두이노 초급연수
#아두이노 초급연수
 
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로
[Main Session] 미래의 Java 미리보기 - 앰버와 발할라 프로젝트를 중심으로
 
이산수학 C1 프로젝트 7
이산수학 C1 프로젝트 7이산수학 C1 프로젝트 7
이산수학 C1 프로젝트 7
 
Javascript개발자의 눈으로 python 들여다보기
Javascript개발자의 눈으로 python 들여다보기Javascript개발자의 눈으로 python 들여다보기
Javascript개발자의 눈으로 python 들여다보기
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
 
13장 연산자 오버로딩
13장 연산자 오버로딩13장 연산자 오버로딩
13장 연산자 오버로딩
 

Viewers also liked

Anay - Fluent interfaces in testing
Anay - Fluent interfaces in testingAnay - Fluent interfaces in testing
Anay - Fluent interfaces in testingvodQA
 
David guetta video
David guetta videoDavid guetta video
David guetta videojackthompson
 
V este web
V este webV este web
V este webAnam
 
Srinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online gameSrinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online gamevodQA
 
Tom palmer
Tom palmerTom palmer
Tom palmersknsz
 
Power point 3 media
Power point 3 mediaPower point 3 media
Power point 3 mediajackthompson
 
Inwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinachInwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinachsknsz
 
Power point 5 media
Power point 5 mediaPower point 5 media
Power point 5 mediajackthompson
 
Web norte
Web norteWeb norte
Web norteAnam
 
01 lb report_presentation
01 lb report_presentation01 lb report_presentation
01 lb report_presentationZla Nala
 
6 da'wah nrosululloh preode makkah
6 da'wah nrosululloh preode makkah6 da'wah nrosululloh preode makkah
6 da'wah nrosululloh preode makkahadulcharli
 
Social Media Board 2010
Social Media Board 2010Social Media Board 2010
Social Media Board 2010Pace
 
Impress carros esportivos
Impress carros esportivosImpress carros esportivos
Impress carros esportivosantoniocs
 
Swiatowyponbrazylia
SwiatowyponbrazyliaSwiatowyponbrazylia
Swiatowyponbrazyliasknsz
 
The Other Half of WWII
The Other Half of WWIIThe Other Half of WWII
The Other Half of WWIIEddie Koelzer
 
Arabskie przebudzenie
Arabskie przebudzenieArabskie przebudzenie
Arabskie przebudzeniesknsz
 

Viewers also liked (20)

Anay - Fluent interfaces in testing
Anay - Fluent interfaces in testingAnay - Fluent interfaces in testing
Anay - Fluent interfaces in testing
 
Fotos de perros
Fotos de perrosFotos de perros
Fotos de perros
 
David guetta video
David guetta videoDavid guetta video
David guetta video
 
V este web
V este webV este web
V este web
 
Srinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online gameSrinivas, Nirmalaya - Testing a massively multi-player online game
Srinivas, Nirmalaya - Testing a massively multi-player online game
 
Tom palmer
Tom palmerTom palmer
Tom palmer
 
Ldap a debian 2: nss i pam
Ldap a debian 2: nss i pamLdap a debian 2: nss i pam
Ldap a debian 2: nss i pam
 
G+
G+G+
G+
 
Power point 3 media
Power point 3 mediaPower point 3 media
Power point 3 media
 
Inwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinachInwestycje zagraniczne w chinach
Inwestycje zagraniczne w chinach
 
Power point 5 media
Power point 5 mediaPower point 5 media
Power point 5 media
 
Web norte
Web norteWeb norte
Web norte
 
01 lb report_presentation
01 lb report_presentation01 lb report_presentation
01 lb report_presentation
 
6 da'wah nrosululloh preode makkah
6 da'wah nrosululloh preode makkah6 da'wah nrosululloh preode makkah
6 da'wah nrosululloh preode makkah
 
Social Media Board 2010
Social Media Board 2010Social Media Board 2010
Social Media Board 2010
 
Impress carros esportivos
Impress carros esportivosImpress carros esportivos
Impress carros esportivos
 
Swiatowyponbrazylia
SwiatowyponbrazyliaSwiatowyponbrazylia
Swiatowyponbrazylia
 
The Other Half of WWII
The Other Half of WWIIThe Other Half of WWII
The Other Half of WWII
 
Arabskie przebudzenie
Arabskie przebudzenieArabskie przebudzenie
Arabskie przebudzenie
 
55ph
55ph55ph
55ph
 

Similar to Cpp 0x kimRyungee

Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국hanbeom Park
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기Sang Heon Lee
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdfkd19h
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdfjinwookhong
 
20150212 c++11 features used in crow
20150212 c++11 features used in crow20150212 c++11 features used in crow
20150212 c++11 features used in crowJaeseung Ha
 
이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3pkok15
 
함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게Gyooha Kim
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++KWANGIL KIM
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer웅식 전
 
Functional programming
Functional programmingFunctional programming
Functional programmingssuserdcfefa
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010MinGeun Park
 
2012 Ds D2 03
2012 Ds D2 032012 Ds D2 03
2012 Ds D2 03chl132435
 
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로Jaeseung Ha
 
2012 Ds D2 03 Pdf
2012 Ds D2 03 Pdf2012 Ds D2 03 Pdf
2012 Ds D2 03 Pdfkd19h
 
Functional programming
Functional programmingFunctional programming
Functional programmingssuserdcfefa
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조영기 김
 
하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2Kwang Yul Seo
 
DEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxDEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxhanbeom Park
 

Similar to Cpp 0x kimRyungee (20)

3.포인터
3.포인터3.포인터
3.포인터
 
Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf
 
이산수학03
이산수학03이산수학03
이산수학03
 
20150212 c++11 features used in crow
20150212 c++11 features used in crow20150212 c++11 features used in crow
20150212 c++11 features used in crow
 
이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3
 
함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 
2012 Ds D2 03
2012 Ds D2 032012 Ds D2 03
2012 Ds D2 03
 
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
 
2012 Ds D2 03 Pdf
2012 Ds D2 03 Pdf2012 Ds D2 03 Pdf
2012 Ds D2 03 Pdf
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조
 
하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2
 
DEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptxDEVIEW-FULL-감독판.pptx
DEVIEW-FULL-감독판.pptx
 

More from scor7910

대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14scor7910
 
Head first statistics ch15
Head first statistics ch15Head first statistics ch15
Head first statistics ch15scor7910
 
Head first statistics ch.11
Head first statistics ch.11Head first statistics ch.11
Head first statistics ch.11scor7910
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기scor7910
 
Mining the social web ch8 - 1
Mining the social web ch8 - 1Mining the social web ch8 - 1
Mining the social web ch8 - 1scor7910
 
Mining the social web ch3
Mining the social web ch3Mining the social web ch3
Mining the social web ch3scor7910
 
Software pattern
Software patternSoftware pattern
Software patternscor7910
 
Google app engine
Google app engineGoogle app engine
Google app enginescor7910
 
Half sync/Half Async
Half sync/Half AsyncHalf sync/Half Async
Half sync/Half Asyncscor7910
 
Component configurator
Component configuratorComponent configurator
Component configuratorscor7910
 
Proxy pattern
Proxy patternProxy pattern
Proxy patternscor7910
 
Reflection
ReflectionReflection
Reflectionscor7910
 

More from scor7910 (12)

대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14대규모 서비스를 지탱하는기술 Ch14
대규모 서비스를 지탱하는기술 Ch14
 
Head first statistics ch15
Head first statistics ch15Head first statistics ch15
Head first statistics ch15
 
Head first statistics ch.11
Head first statistics ch.11Head first statistics ch.11
Head first statistics ch.11
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기
 
Mining the social web ch8 - 1
Mining the social web ch8 - 1Mining the social web ch8 - 1
Mining the social web ch8 - 1
 
Mining the social web ch3
Mining the social web ch3Mining the social web ch3
Mining the social web ch3
 
Software pattern
Software patternSoftware pattern
Software pattern
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
Half sync/Half Async
Half sync/Half AsyncHalf sync/Half Async
Half sync/Half Async
 
Component configurator
Component configuratorComponent configurator
Component configurator
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Reflection
ReflectionReflection
Reflection
 

Cpp 0x kimRyungee

  • 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
  • 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), [](int n) -> 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 Reference double& rd1 = 2.0; const double& rd2 = 2.0; double&& rd3 = 2.0; rd2 += 1; rd3 +=3;
  • 19. R-Value Reference double& 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. auto for (vector<int>::const_iterator itr = myvec.begin(); itr != myvec.end(); ++itr) for (auto itr = myvec.begin(); itr != myvec.end(); ++itr)
  • 22. decltype const int&& foo(); int i; struct A { double x; }; const A* a = new A(); decltype(foo()) x1 = i; // x1 타입은 const int&& decltype(i) x2; // x2 타입은 int decltype(a->x) x3; // x3 타입은 double decltype((a->x)) x4 = x3; // x4 타입은 double&
  • 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