VC2013 C11C14C17 C11 Rvalue references refqualifiers constexpr Casyncawait

  • Slides: 49
Download presentation

VC++2013事情 C++11/C++14/C++17(予定) C++11 Rvalue references (対応完了) ref-qualifiers constexpr (一部) C#のasync/awaitを意識 Alignment Inheriting constructors Defaulted

VC++2013事情 C++11/C++14/C++17(予定) C++11 Rvalue references (対応完了) ref-qualifiers constexpr (一部) C#のasync/awaitを意識 Alignment Inheriting constructors Defaulted and deleted functions (対応完了) Extended sizeof C++14 noexcept (一部) auto and decltype(auto) return types C++11 Concurrency Generic lambdas (一部) Magic statics C++11 C 99 __func__ (対応完了) C++17 (予定) Concurrency TS(? ) Resumable functions and await (一部)

3. Visual Studio 2013 VC++

3. Visual Studio 2013 VC++

VC++2013 プロジェクト 種類 例 C++ 非同期処理 VC++ Windows Runtime 並列 高速演算 C++11 <future> 機能の例

VC++2013 プロジェクト 種類 例 C++ 非同期処理 VC++ Windows Runtime 並列 高速演算 C++11 <future> 機能の例 std: : thread / std: : promise std: : async C++/CX concurrency: : task ppltasks. h Direct. X C++AMP (GPGPU利用) amp. h concurrency: : parallel_for_each

C++余談 Lambda grammer

C++余談 Lambda grammer

Classic C #include <stdio. h> int main() { printf( “Hello Worldn” ); return 0;

Classic C #include <stdio. h> int main() { printf( “Hello Worldn” ); return 0; }

C++03 #include <iostream> int main() { std: : cout << “Hello World. ” <<

C++03 #include <iostream> int main() { std: : cout << “Hello World. ” << std: : endl; return 0; }

C++11 (1) int main() { [ ]{ std: : cout << “Hello World!” <<

C++11 (1) int main() { [ ]{ std: : cout << “Hello World!” << std: : endl; }( ); return 0; }

C++11 (3) int main() { [ ]( std: : string const &str ) //

C++11 (3) int main() { [ ]( std: : string const &str ) // 引数 { std: : cout << str << std: : endl; } // コード ( “Hello World!” ); // 呼び出し } return 0;

C++14 generic lambda int main() { auto plus = [ ]( auto x, auto

C++14 generic lambda int main() { auto plus = [ ]( auto x, auto y ) { return x + y; }; plus( 5, 5 ); plus( std: : string( "Hello “ ), std: : string( "World“ )); } return 0;

concurrency: : task sample #include "stdafx. h“ #include <iostream> std: : asyncと同じ形 #include <ppltasks.

concurrency: : task sample #include "stdafx. h“ #include <iostream> std: : asyncと同じ形 #include <ppltasks. h> // <future>でもOK int main( ){ int num = 0; concurency: : task<int>t 01([ &num ](){ // taskで別タスク実行 ++ num; return( num ); // 非同期処理で返すものを設定 }); int result = t 01. get(); // 同期を取る return( 0 ); }

. then()を用いたTask のつなげ方 (1) concurency: : task<int> t 1([]() { return( 1 ); });

. then()を用いたTask のつなげ方 (1) concurency: : task<int> t 1([]() { return( 1 ); }); 型は合わせること concurency: : task<int> t 2 = t 1. then([](int n) { return( ++n ); }); concurency: : task<int> t 3 = t 2. then([](int n) { return( ++n ); }); int result = t 3. get(); // 同期 . then で返り値を 別のタスクに渡す どんどんつなげることが 可能

VC++非同期処理(2) pplawait. h の resumable / await を使ってみる

VC++非同期処理(2) pplawait. h の resumable / await を使ってみる

VC++非同期処理 resumable / await C#の async/await の C++版 Visual C++ Compiler November 2013 CTP

VC++非同期処理 resumable / await C#の async/await の C++版 Visual C++ Compiler November 2013 CTP http: //aka. ms/Icp 591

resumable/await Sample #include <future> #include <pplawait. h> concurrency: : task<void> my_proc(void) __resumable{ auto x

resumable/await Sample #include <future> #include <pplawait. h> concurrency: : task<void> my_proc(void) __resumable{ auto x = []() __resumable -> concurrency: : task<void> { std: : cout << “abc. " << std: : endl; }; __await x(); std: : cout << “def. " << std: : endl; } int main() { auto task = my_proc(); task. wait(); }

C++/CX Sample. then版 void App 1: : Main. Page: : my_btn_click( Platform: : Object^

C++/CX Sample. then版 void App 1: : Main. Page: : my_btn_click( Platform: : Object^ sender, Windows: : UI: : Xaml: : Routed. Event. Args^ e) { task<Storage. File^>( Known. Folders: : Documents. Library->Create. File. Async( my_txt->Text , Creation. Collision. Option: : Replace. Existing) ). then([this](Storage. File^ file) { my_btn_01 ->Content = "ファイル作成しました"; }); }

C++/CX Sample resumable/await版 concurrency: : task<void> App 1: : Main. Page: : my_btn_click( Platform:

C++/CX Sample resumable/await版 concurrency: : task<void> App 1: : Main. Page: : my_btn_click( Platform: : Object^ sender, Windows: : UI: : Xaml: : Routed. Event. Args^ e)__resumable { auto file = __await file->Create. File. Async( my_txt->Text, Creation. Collision. Option: : Replace. Existing); my_btn_01 ->Content = "ファイル作成しました"; }

非同期構成/操作概念 App container ( package manifest ) UI controls ( XAML ) 他の Windows

非同期構成/操作概念 App container ( package manifest ) UI controls ( XAML ) 他の Windows Runtimeと 非同期通信 C++/CX C++実装クラス (ネイティブ) concurrency: : task Windows: : Foundation: : IAsync. Actionなど concurrency: : create_async

Windows. Runtimeで用意しているTask 4つの非同期インターフェース Windows: : Foundation 他の言語ともやり取りできる 非同期アクション IAsync. Action 非同期進行状況 IAsync. Action. With.

Windows. Runtimeで用意しているTask 4つの非同期インターフェース Windows: : Foundation 他の言語ともやり取りできる 非同期アクション IAsync. Action 非同期進行状況 IAsync. Action. With. Progress<TProgress> 結果を返す非同期 IAsync. Operation<TResult> 結果も返すし進行 も判る IAsync. Operation. With. Progress<TResult, TProgress>

Windows Store Apps demo

Windows Store Apps demo

XAMLからのクリックイベント(1) <Button x: Name="Sort. Button" Content="Sort" Click="Sort. Button_Click"/>

XAMLからのクリックイベント(1) <Button x: Name="Sort. Button" Content="Sort" Click="Sort. Button_Click"/>

XAMLからのクリックイベント(2) void Scenario. Input 1: : Sort. Button_Click(Platform: : Object^ sender, Windows: : UI:

XAMLからのクリックイベント(2) void Scenario. Input 1: : Sort. Button_Click(Platform: : Object^ sender, Windows: : UI: : Xaml: : Routed. Event. Args^ e){ Sort. Button->Is. Enabled = false; textblock->Text = "ソート中(*´Д`). . . "; sort. Vector = Extract. Ints( Textbox->Text ); create_task([this] { Merge. Sort( sort. Vector. begin(), sort. Vector. end() ); } }). then( [this] { textblock->Text = Make. String( sort. Vector ); この場合の. thenは、 Sort. Button->Is. Enabled = true; UIスレッドに返している }, task_continuation_context: : use_current()); 別のスレッドプールを指定する ことも出来る

参考 Hilo での非同期プログラミング パターンとヒント (C++ と XAML を使っ た Windows ストア アプリ) http: //msdn.

参考 Hilo での非同期プログラミング パターンとヒント (C++ と XAML を使っ た Windows ストア アプリ) http: //msdn. microsoft. com/ja-jp/library/windows/apps/jj 160321. aspx C++ における Windows ストア アプリ用の非同期操作の作成 http: //msdn. microsoft. com/ja-jp/library/windows/apps/hh 750082. aspx C++AMPを用いたGPUプログラミング http: //www. aerospace. sd. tmu. ac. jp/hydrodynamics/main/colums/AMPinde x. html Windows 8 Asynchronous Operations in C++ with PPL http: //code. msdn. microsoft. com/windowsapps/Windows-8 -Asynchronous 08009 a 0 d