SlideShare une entreprise Scribd logo
1  sur  16
パッと見でわかる C++11



       わんくま同盟茶藝部顧問
       episthmh episteme@cppll.jp


プログラミング生放送勉強会 第17回@品川
episthmhて何者ぞ
•   C++界隈ではちったー名の知れたソフト屋
•   Microsot MVP for Visual C++ 2004~
•   モノ書き? DDJJ, C-Magazine… CodeZine
•   書籍いくつか




       プログラミング生放送勉強会 第17回@品川
Visual Studio (VC++) と C++11

• Visual Studio 2010 は
  – C++11 の”いくつか”をサポート


• Visual Studio 2012 では
  –   言語レベルでの強化 と
  –   ライブラリ追加 によって
  –   より C++11 に迫っています
  –   “フルコンプ”じゃないけどね


       プログラミング生放送勉強会 第17回@品川
array<T,N>




int data[N] = { 1, 2, 3 };
for_each( data, data+N, … );


array<int,N> data = { 1, 2, 3 };
for_each( data.begin(), data.end(), … );



                         begin(), end(), size() などなど、
                         container系メンバ関数が使えます。



 プログラミング生放送勉強会 第17回@品川
begin(), end()

vector<int> v;
int a[N] ;
for_each( v.begin(), v.end(), … );
for_each( a, a+N, …)


vector<int> v;
int a[N];
for_each( begin(v), end(v), … );
for_each( begin(a), end(a), …);

                         containerと思しきもののアタマとケツは、
                         begin()/end() で統一できます。



 プログラミング生放送勉強会 第17回@品川
auto

vector<int> v;
for ( vector<int>::iterator iter = v.begin();
        iter != v.end(); ++iter ) {
  cout << *iter << endl;
}

vector<int> v;
for ( auto iter = v.begin(); iter != v.end(); ++iter ) {
  cout << *iter << endl;
}
                             「型推論」
                             ずっと欲しかった機能。



  プログラミング生放送勉強会 第17回@品川
range-based for

vector<int> v;
for ( vector<int>::iterator iter = v.begin();
        iter != v.end(); ++iter ) {
  cout << *iter << endl;
}

vector<int> v;                 vector<int> v;
for ( int item : v ) {         for ( auto item : v ) {
  cout << item << endl;          cout << item << endl;
}                              }

                  begin(), end() が適用できるcontainerと思しきもの
                  であれば、range-based for が使えます。



 プログラミング生放送勉強会 第17回@品川
foreach(.NET) にはできないこと




vector<int> v;            vector<int> v;
for ( int& item : v ) {   for ( auto& item : v ) {
  ++item;                   ++item;
}                         }




                             「参照」できちゃうですね♪


プログラミング生放送勉強会 第17回@品川
lambda式

void print_int(int item) { cout << item << endl; }
…
vector<int> v;
for_each( v.begin(), v.end(), print_int);


vector<int> v;
for_each( v.begin(), v.end(),
            [](int item) { cout << item << endl; }
         );


                     関数オブジェクトをその場で定義しちゃうです。


 プログラミング生放送勉強会 第17回@品川
stateless-lambdaは関数ポインタに暗黙変換できる

  int main() {
    const int N = 10;
    int data[N] = { 9, 7, 5, 3, 1, 0, 2, 4, 6, 8 };
    // qsortの比較関数にlambdaをねじ込む
    qsort(data, N, sizeof(int),
         [](const void* x, const void* y)->int
           { return *static_cast<const int*>(x)
                        - *static_cast<const int*>(y);}
        );
    for ( auto item : data ) {cout << item << ' '; }
    cout << endl;
  }
                    stateless-lambda: なにもキャプチャしないlambda


   プログラミング生放送勉強会 第17回@品川
stateless-lambdaは関数ポインタに暗黙変換できる

 wcout.imbue(locale("japanese"));
  // EnumWindows に与える CALLBACK に stateless lambda を。
  EnumWindows(
    [](HWND hWnd, LPARAM lParam)->BOOL {
      TCHAR buf[256];
      GetWindowText(hWnd, buf, 256);
      if ( buf[0] != L'0' ) {
        *reinterpret_cast<wostream*>(lParam)
           << buf << endl;
      }
      return TRUE;
    },
    reinterpret_cast<LPARAM>(&wcout));

                        __cdecl, __stdcall のどちらにも使えます。


    プログラミング生放送勉強会 第17回@品川
Win-API によるスレッド
// スレッド本体
int plus(int x, int y) {   return x + y;   }

// Win32 thread のためのwrapper
typedef tuple<int,int,int> thread_io;

DWORD WINAPI plus_entry(LPVOID argv) {
  thread_io* io = static_cast<thread_io*>(argv);
  get<2>(*io) = plus(get<0>(*io),get<1>(*io));
  return 0;
}

int main() {
  HANDLE handle;
  thread_io pio(1,2,0);
  handle = CreateThread(NULL, 0, &plus_entry, &pio, 0, NULL);
  WaitForSingleObject(handle, INFINITE);
  CloseHandle(handle);
  cout << get<2>(pio) << endl;
}                                 従来のスレッドは wrapper を必要とし
                                           ます

   プログラミング生放送勉強会 第17回@品川
<thread>
#include <iostream>
#include <thread>

using namespace std;

int plus_int(int x, int y) { return x + y; }

int main() {
  int result;
  thread thr([&](int x, int y) { result = plus_int(x,y);}, 1, 2);
  thr.join();
  cout << result << endl;
}                                コンストラクタに与えた関数オブジェ
                               クトを
                               スレッドで実行します。

      プログラミング生放送勉強会 第17回@品川
<future>
#include <iostream>
#include <future>

using namespace std;

int plus_int(int x, int y) { return x + y; }

int main() {
  future<int> f = async(plus_int, 1, 2);
  cout << f.get() << endl;
}
                                asyncでスレッドを生成/実行
                                し、
                                futureでその結果を受け取りま
                                す。
  プログラミング生放送勉強会 第17回@品川
<mutex>
#include <mutex>
…

mutex mtx;
int balance = 0;

void plus_int(int x)
 { lock_guard<mutex> guard(mtx); balance += x; }

int main() {
  thread thr_inc([&](int n) { while ( n-- ) plus_int( 1);}, 1000000);
  thread thr_dec([&](int n) { while ( n-- ) plus_int(-1);}, 1000000);
  thr_inc.join();
  thr_dec.join();
  cout << balance << endl;
}                                      Win-API の CriticalSection 相当。


  プログラミング生放送勉強会 第17回@品川
<atomic>
#include <thread>
#include <atomic>

using namespace std;

int main() {
  atomic<int> balance = 0;
  thread thr_inc([&](int n) { while ( n-- ) ++balance; }
            , 1000000);
  thread thr_dec([&](int n) { while ( n-- ) --balance; }
            , 1000000);
  thr_inc.join();
  thr_dec.join();
  cout << balance << endl;
}
                                     Win-API の InterlockedXXX 相
                                     当。

  プログラミング生放送勉強会 第17回@品川

Contenu connexe

Tendances

言語処理系入門€10
言語処理系入門€10言語処理系入門€10
言語処理系入門€10Kenta Hattori
 
関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPUTakuro Iizuka
 
Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Keisuke Fukuda
 
きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回Tomoya Kawanishi
 
Cython intro prelerease
Cython intro prelereaseCython intro prelerease
Cython intro prelereaseShiqiao Du
 
Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Mr. Vengineer
 
C++入門?
C++入門?C++入門?
C++入門?tsudaa
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案yohhoy
 
NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門Shiqiao Du
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由kikairoya
 
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)Takeshi Yamamuro
 
Wrapping a C++ library with Cython
Wrapping a C++ library with CythonWrapping a C++ library with Cython
Wrapping a C++ library with Cythonfuzzysphere
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチンyohhoy
 

Tendances (20)

言語処理系入門€10
言語処理系入門€10言語処理系入門€10
言語処理系入門€10
 
llvm入門
llvm入門llvm入門
llvm入門
 
関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU
 
Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35
 
きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回きつねさんでもわかるLlvm読書会 第2回
きつねさんでもわかるLlvm読書会 第2回
 
Cython intro prelerease
Cython intro prelereaseCython intro prelerease
Cython intro prelerease
 
Map
MapMap
Map
 
Emcjp item21
Emcjp item21Emcjp item21
Emcjp item21
 
Emcpp item31
Emcpp item31Emcpp item31
Emcpp item31
 
C++14 Overview
C++14 OverviewC++14 Overview
C++14 Overview
 
Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析
 
emc++ chapter32
emc++ chapter32emc++ chapter32
emc++ chapter32
 
C++入門?
C++入門?C++入門?
C++入門?
 
新しい並列for構文のご提案
新しい並列for構文のご提案新しい並列for構文のご提案
新しい並列for構文のご提案
 
NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門NumPyが物足りない人へのCython入門
NumPyが物足りない人へのCython入門
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
 
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
 
Wrapping a C++ library with Cython
Wrapping a C++ library with CythonWrapping a C++ library with Cython
Wrapping a C++ library with Cython
 
Effective modern-c++#9
Effective modern-c++#9Effective modern-c++#9
Effective modern-c++#9
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン
 

Similaire à ぱっと見でわかるC++11

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
わんくま同盟大阪勉強会#61
わんくま同盟大阪勉強会#61わんくま同盟大阪勉強会#61
わんくま同盟大阪勉強会#61TATSUYA HAYAMIZU
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターンMoriharu Ohzu
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputingNoboru Irieda
 
.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#信之 岩永
 
Unity C#3からC#6に向けて
Unity C#3からC#6に向けてUnity C#3からC#6に向けて
Unity C#3からC#6に向けてonotchi_
 
動的計画法の並列化
動的計画法の並列化動的計画法の並列化
動的計画法の並列化Proktmr
 
2018/06/23 Sony"s deep learning software and the latest information
2018/06/23 Sony"s deep learning software and the latest information2018/06/23 Sony"s deep learning software and the latest information
2018/06/23 Sony"s deep learning software and the latest informationSony Network Communications Inc.
 
最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)Akihiko Matuura
 
Node.jsでつくるNode.js ミニインタープリター&コンパイラー
Node.jsでつくるNode.js ミニインタープリター&コンパイラーNode.jsでつくるNode.js ミニインタープリター&コンパイラー
Node.jsでつくるNode.js ミニインタープリター&コンパイラーmganeko
 
show コマンド結果をパースする方法あれこれ #npstudy
show コマンド結果をパースする方法あれこれ #npstudyshow コマンド結果をパースする方法あれこれ #npstudy
show コマンド結果をパースする方法あれこれ #npstudyakira6592
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Springanyakichi
 
C++0xの概要(デブサミ2010)
C++0xの概要(デブサミ2010)C++0xの概要(デブサミ2010)
C++0xの概要(デブサミ2010)Akira Takahashi
 
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)Shin-ya Koga
 
函数プログラミングの エッセンスと考え方
函数プログラミングのエッセンスと考え方函数プログラミングのエッセンスと考え方
函数プログラミングの エッセンスと考え方啓 小笠原
 
C++0x 言語の未来を語る
C++0x 言語の未来を語るC++0x 言語の未来を語る
C++0x 言語の未来を語るAkira Takahashi
 
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目hecomi
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)ryos36
 
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...Masahiro Sakai
 

Similaire à ぱっと見でわかるC++11 (20)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
わんくま同盟大阪勉強会#61
わんくま同盟大阪勉強会#61わんくま同盟大阪勉強会#61
わんくま同盟大阪勉強会#61
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターン
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputing
 
Pfi Seminar 2010 1 7
Pfi Seminar 2010 1 7Pfi Seminar 2010 1 7
Pfi Seminar 2010 1 7
 
.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#.NET Core 2.x 時代の C#
.NET Core 2.x 時代の C#
 
Unity C#3からC#6に向けて
Unity C#3からC#6に向けてUnity C#3からC#6に向けて
Unity C#3からC#6に向けて
 
動的計画法の並列化
動的計画法の並列化動的計画法の並列化
動的計画法の並列化
 
2018/06/23 Sony"s deep learning software and the latest information
2018/06/23 Sony"s deep learning software and the latest information2018/06/23 Sony"s deep learning software and the latest information
2018/06/23 Sony"s deep learning software and the latest information
 
最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)最新C++事情 C++14-C++20 (2018年10月)
最新C++事情 C++14-C++20 (2018年10月)
 
Node.jsでつくるNode.js ミニインタープリター&コンパイラー
Node.jsでつくるNode.js ミニインタープリター&コンパイラーNode.jsでつくるNode.js ミニインタープリター&コンパイラー
Node.jsでつくるNode.js ミニインタープリター&コンパイラー
 
show コマンド結果をパースする方法あれこれ #npstudy
show コマンド結果をパースする方法あれこれ #npstudyshow コマンド結果をパースする方法あれこれ #npstudy
show コマンド結果をパースする方法あれこれ #npstudy
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Spring
 
C++0xの概要(デブサミ2010)
C++0xの概要(デブサミ2010)C++0xの概要(デブサミ2010)
C++0xの概要(デブサミ2010)
 
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
 
函数プログラミングの エッセンスと考え方
函数プログラミングのエッセンスと考え方函数プログラミングのエッセンスと考え方
函数プログラミングの エッセンスと考え方
 
C++0x 言語の未来を語る
C++0x 言語の未来を語るC++0x 言語の未来を語る
C++0x 言語の未来を語る
 
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)
 
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
 

Plus de えぴ 福田

Plus de えぴ 福田 (7)

Yokohama6 epi
Yokohama6 epiYokohama6 epi
Yokohama6 epi
 
.NETラボ 2013-12-21 LT
.NETラボ 2013-12-21 LT.NETラボ 2013-12-21 LT
.NETラボ 2013-12-21 LT
 
Episteme unique_ptr
Episteme unique_ptrEpisteme unique_ptr
Episteme unique_ptr
 
Episteme variadic template
Episteme variadic templateEpisteme variadic template
Episteme variadic template
 
T77 episteme
T77 epistemeT77 episteme
T77 episteme
 
T45 episteme
T45 epistemeT45 episteme
T45 episteme
 
T69 episteme
T69 epistemeT69 episteme
T69 episteme
 

Dernier

TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 

Dernier (9)

TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 

ぱっと見でわかるC++11

  • 1. パッと見でわかる C++11 わんくま同盟茶藝部顧問 episthmh episteme@cppll.jp プログラミング生放送勉強会 第17回@品川
  • 2. episthmhて何者ぞ • C++界隈ではちったー名の知れたソフト屋 • Microsot MVP for Visual C++ 2004~ • モノ書き? DDJJ, C-Magazine… CodeZine • 書籍いくつか プログラミング生放送勉強会 第17回@品川
  • 3. Visual Studio (VC++) と C++11 • Visual Studio 2010 は – C++11 の”いくつか”をサポート • Visual Studio 2012 では – 言語レベルでの強化 と – ライブラリ追加 によって – より C++11 に迫っています – “フルコンプ”じゃないけどね プログラミング生放送勉強会 第17回@品川
  • 4. array<T,N> int data[N] = { 1, 2, 3 }; for_each( data, data+N, … ); array<int,N> data = { 1, 2, 3 }; for_each( data.begin(), data.end(), … ); begin(), end(), size() などなど、 container系メンバ関数が使えます。 プログラミング生放送勉強会 第17回@品川
  • 5. begin(), end() vector<int> v; int a[N] ; for_each( v.begin(), v.end(), … ); for_each( a, a+N, …) vector<int> v; int a[N]; for_each( begin(v), end(v), … ); for_each( begin(a), end(a), …); containerと思しきもののアタマとケツは、 begin()/end() で統一できます。 プログラミング生放送勉強会 第17回@品川
  • 6. auto vector<int> v; for ( vector<int>::iterator iter = v.begin(); iter != v.end(); ++iter ) { cout << *iter << endl; } vector<int> v; for ( auto iter = v.begin(); iter != v.end(); ++iter ) { cout << *iter << endl; } 「型推論」 ずっと欲しかった機能。 プログラミング生放送勉強会 第17回@品川
  • 7. range-based for vector<int> v; for ( vector<int>::iterator iter = v.begin(); iter != v.end(); ++iter ) { cout << *iter << endl; } vector<int> v; vector<int> v; for ( int item : v ) { for ( auto item : v ) { cout << item << endl; cout << item << endl; } } begin(), end() が適用できるcontainerと思しきもの であれば、range-based for が使えます。 プログラミング生放送勉強会 第17回@品川
  • 8. foreach(.NET) にはできないこと vector<int> v; vector<int> v; for ( int& item : v ) { for ( auto& item : v ) { ++item; ++item; } } 「参照」できちゃうですね♪ プログラミング生放送勉強会 第17回@品川
  • 9. lambda式 void print_int(int item) { cout << item << endl; } … vector<int> v; for_each( v.begin(), v.end(), print_int); vector<int> v; for_each( v.begin(), v.end(), [](int item) { cout << item << endl; } ); 関数オブジェクトをその場で定義しちゃうです。 プログラミング生放送勉強会 第17回@品川
  • 10. stateless-lambdaは関数ポインタに暗黙変換できる int main() { const int N = 10; int data[N] = { 9, 7, 5, 3, 1, 0, 2, 4, 6, 8 }; // qsortの比較関数にlambdaをねじ込む qsort(data, N, sizeof(int), [](const void* x, const void* y)->int { return *static_cast<const int*>(x) - *static_cast<const int*>(y);} ); for ( auto item : data ) {cout << item << ' '; } cout << endl; } stateless-lambda: なにもキャプチャしないlambda プログラミング生放送勉強会 第17回@品川
  • 11. stateless-lambdaは関数ポインタに暗黙変換できる wcout.imbue(locale("japanese")); // EnumWindows に与える CALLBACK に stateless lambda を。 EnumWindows( [](HWND hWnd, LPARAM lParam)->BOOL { TCHAR buf[256]; GetWindowText(hWnd, buf, 256); if ( buf[0] != L'0' ) { *reinterpret_cast<wostream*>(lParam) << buf << endl; } return TRUE; }, reinterpret_cast<LPARAM>(&wcout)); __cdecl, __stdcall のどちらにも使えます。 プログラミング生放送勉強会 第17回@品川
  • 12. Win-API によるスレッド // スレッド本体 int plus(int x, int y) { return x + y; } // Win32 thread のためのwrapper typedef tuple<int,int,int> thread_io; DWORD WINAPI plus_entry(LPVOID argv) { thread_io* io = static_cast<thread_io*>(argv); get<2>(*io) = plus(get<0>(*io),get<1>(*io)); return 0; } int main() { HANDLE handle; thread_io pio(1,2,0); handle = CreateThread(NULL, 0, &plus_entry, &pio, 0, NULL); WaitForSingleObject(handle, INFINITE); CloseHandle(handle); cout << get<2>(pio) << endl; } 従来のスレッドは wrapper を必要とし ます プログラミング生放送勉強会 第17回@品川
  • 13. <thread> #include <iostream> #include <thread> using namespace std; int plus_int(int x, int y) { return x + y; } int main() { int result; thread thr([&](int x, int y) { result = plus_int(x,y);}, 1, 2); thr.join(); cout << result << endl; } コンストラクタに与えた関数オブジェ クトを スレッドで実行します。 プログラミング生放送勉強会 第17回@品川
  • 14. <future> #include <iostream> #include <future> using namespace std; int plus_int(int x, int y) { return x + y; } int main() { future<int> f = async(plus_int, 1, 2); cout << f.get() << endl; } asyncでスレッドを生成/実行 し、 futureでその結果を受け取りま す。 プログラミング生放送勉強会 第17回@品川
  • 15. <mutex> #include <mutex> … mutex mtx; int balance = 0; void plus_int(int x) { lock_guard<mutex> guard(mtx); balance += x; } int main() { thread thr_inc([&](int n) { while ( n-- ) plus_int( 1);}, 1000000); thread thr_dec([&](int n) { while ( n-- ) plus_int(-1);}, 1000000); thr_inc.join(); thr_dec.join(); cout << balance << endl; } Win-API の CriticalSection 相当。 プログラミング生放送勉強会 第17回@品川
  • 16. <atomic> #include <thread> #include <atomic> using namespace std; int main() { atomic<int> balance = 0; thread thr_inc([&](int n) { while ( n-- ) ++balance; } , 1000000); thread thr_dec([&](int n) { while ( n-- ) --balance; } , 1000000); thr_inc.join(); thr_dec.join(); cout << balance << endl; } Win-API の InterlockedXXX 相 当。 プログラミング生放送勉強会 第17回@品川