C++11概要 ライブラリ編

Similar documents
新版 明解C++入門編

C 1

1 C++ 2 Bjarne Stroustrup C++ (system programming) 6 (infrastructure) C++ 7 Herb Sutter 8 C++ (efficiency) (flexibility) 9 (abstraction) (productivity

C/C++程序设计 - 字符串与格式化输入/输出

CC213

新・明解C言語入門編『索引』

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

untitled

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

FY.DOC

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

新版 明解C言語入門編

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

新・解きながら学ぶC言語

C/C++语言 - C/C++数据

c_cpp

02

C/C++ - 文件IO

untitled

(Microsoft Word - 11\244T\246\342\277\337\260l\302\334.doc)

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

untitled

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

extend

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

第3章.doc

CHAPTER VC#

新・解きながら学ぶJava

C

ebook50-15

C/C++ - 字符输入输出和字符确认

华恒家庭网关方案

C/C++ - 字符串与字符串函数

Microsoft Word - CPE考生使用手冊 docx

Microsoft Word cppFinalSolution.doc

IO

untitled

Microsoft Word - 第3章.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

数据结构与算法 - Python基础

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

3.1 num = 3 ch = 'C' 2

C/C++ - 结构体、共用体、枚举体

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

untitled

untitled

提问袁小兵:

C C

Microsoft PowerPoint - L17_Inheritance_v4.pptx

ebook50-14

C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

PowerPoint Presentation

( 二 ) 拓 展 岗 位 ( 群 ) 1. 餐 厅 服 务 岗 位 群 在 大 中 型 餐 饮 企 业 星 级 饭 店 主 要 从 事 餐 饮 服 务 的 有 关 工 作, 如 服 务 员 点 菜 师 茶 艺 师 咖 啡 师 调 酒 师 等 2. 食 品 加 工 岗 位 群 主 要 从 事 餐 饮

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1

C++ 程式設計

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

51 C 51 isp 10 C PCB C C C C KEIL

C/C++ - 函数

中北大学常规事项财务报销操作指南

Microsoft Word - 01.DOC

mvc

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

untitled

Microsoft PowerPoint - string_kruse [兼容模式]

プログラムの設計と実現II

公開徵求廠商提供「採購專業人員訓練計畫企劃書」公告

untitled

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Microsoft Word - ch04三校.doc

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

CHAPTER 1

一量动…

untitled

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

SA-CPCB81TRA-CN (Panduit INdustrial Automation Solutions).indd

Chapter12 Derived Classes

Microsoft Word - 正文部分.doc

untitled

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

考 試 日 期 :2016/04/24 教 室 名 稱 :602 電 腦 教 室 考 試 時 間 :09: 二 技 企 管 一 胡 宗 兒 中 文 輸 入 四 技 企 四 甲 林 姿 瑄 中 文 輸 入 二 技 企 管 一

Strings

Microsoft PowerPoint - 10 模板 Template.pptx

1 C++ Bjarne Stroustrupp5 C++ C++ Qt p10 Trolltech WINDOWS Qt C++ p11 VC Wizard C++BCB C++ p17 STL Traits p19 C++ View C++ p25 Smart Pointer p27

《佛子行三十七颂》讲记1

至 尊 法 王 蒋 阳 龙 朵 加 参 尊 者 上 师 瑜 伽 皈 依 境

(给多有拉姆)佛子行三十七颂1——7

Microsoft Word - CIN-DLL.doc

Eclipse C C++, or

C

第 一 节 认 识 自 我 的 意 义 一 个 人 只 有 认 识 自 我, 才 能 够 正 确 地 认 识 到 自 己 的 优 劣 势, 找 出 自 己 的 职 业 亮 点, 为 自 己 的 顺 利 求 职 推 波 助 澜 ; 一 个 人 只 有 认 识 自 我, 才 能 在 求 职 中 保 持

PowerPoint Presentation

1.5招募说明书(草案)

CC213

untitled

Microsoft Word - 1-3陳詠琳-近代..

第十一届“21世纪杯”全国中小学生英语演讲比赛

C/C++ 语言 - 循环

nooog

Transcription:

C++11 Egtra 2012 6 23 1 Boost. #9 1.1 C++11 1.2 http://creativecommons.org/licenses/by-sa/2.1/jp/ - 2.1 2 Misc 2.1 C++11 unique_ptr shared_ptr // #include <memory> std::unique_ptr<int> up(new int(1)); 1

std::unique_ptr<int[]> ua(new int[]{1, 2, 3}); auto sp = std::make_shared<int>(3); unique_ptr std::auto_ptr boost::scoped_ptr boost::scoped_array std::vector unique_ptr auto_ptr shared_ptr boost::shared_ptr shared_ptr make_shared make_shared std::make_shared<int> int 1 shared_ptr new std::shared_ptr<int> sp2(new int(4)); boost::shared_array 2.2 Boost std::function std::ref std::bind std::mem_fn bind bind 2

2.3 (C99) C++11 C99 <cstdint> typedef <cstdint> std::int8_t, std::uint8_t std::int16_t, std::uint16_t std::int32_t, std::uint32_t std::int64_t, std::uint64_t typedef intptr_t uintptr_t 32 64 int_fast8_t 8 CPU 16 32 int_least8_t 8 int8_t intmax_t 8163264 intmax_t 2.4 C++11 C rand 3

: C++0x random http://cpplover.blogspot.jp/2009/11/c0xrandom.html 3 3.1 Unordered unordered_map unordered_multimap unordered_set unordered_multiset array boost::array forward_list unordered hash_map unordered map set Unordered map set insert erase unordered_map [] 3.2 // #include <array> // #include <vector> int ra[] = {1, 2, 3 std::array<int, 3> a = {1, 2, 3 4

std::vector<int> v = {1, 2, 3 a = {4, 5, 6 v = {4, 5, 6 3.2.1 Point struct Point { double x; double y; push_backinsert std::vector<point> vp = { {10, 0}, {0, 20}, vp.push_back({0, 20}); vp.insert(v.begin(), {0, 0}); deque list push_front 3.2.2 class RailwayLine { public: RailwayLine( std::string const& start, std::string const& end); 5

std::vector<railwayline> line = { {"Akihabara", "Tsukuba"}, line RailwayLine("Akihabara", "Tsukuba") 3.2.3 fstream stringstream std::vector<std::fstream> vf = { std::fstream("a.cpp"), std::fstream("a.out", std::ios_base::binary), explicit {"a.cpp"} Thank you: @Flast_RO by https://twitter.com/flast_ro/status/206280203046105088 3.2.4 emplace_back class SanJigen : boost::noncopyable { public: SanJigen(int x, int y, int z); emplace_back // std::set<sanjigen> figure; figure.emplace_back(3, 1, 4); // figure[0] == SanJigen(3, 1, 4) 6

emplace_back vector vector vector Thank you: @SubaruG 3.3 map::at unordered_map::at map unordered_map [] const const const at at vector deque #include <unordered_map> std::map<std::string, std::string> const yome = { {"Nyaruko", "Mahiro"}, {"Kuko", "Nyaruko"}, {"Hasta", "Mahiro"}, auto x = yome.at("hasta"); // x == "Mahiro" "Hasta""Mahiro" at vector at std::out_of_range yome.at("mahiro"); // std::out_of_range "Mahiro" map at auto const yome2 = yome; yome2.insert({"mahiro", "Shantak-kun"}); auto y = yome2.at("mahiro"); 7

3.4 unordered_map std::unordered_map unordered My::Point namespace My { struct Point { int x, y; } std::hash namespace My { bool operator==(point, Point); } namespace std { struct hash<my::point> { std::size_t operator()(point const& pt) const { return ; } // } Unorderd std::unordered_map<my::point, SanJigen> position; std::unordered_map std::map < std::map 8

4 4.1 basic_string std::basic_string (std::stringstd::wstringstd::u16string std::u32string) std::vector std::array Windows GetWindowText 2 TCHAR*TCHAR basic_string<tchar> // int GetWindowText(HWND hwnd, THCAR*, int); auto len = GetWindowTextLength(hwnd); std::basic_string<tchar> t(len + 1); auto actuallength = GetWindowText(hwnd, &s[0], len + 1); s.resize(actuallength); s.pop_back(); GetWindowText Thank you: @melponn 4.2 std::string std::wstring 4.3 stoi atoi strtol // #include <string> int stoi(const std::string& str, 9

std::size_t* idx = 0, int base = 10); int stoi(const std::wstring& str, std::size_t* idx = 0, int base = 10); // atoi auto x = stoi("103"); // strtol std::size_t pos; auto y = stoi("beef kue", &pos, 16); stoi int stoi int stol long stoll long long stoull unsigned long long stof float stod double stold long double 4.4 to_string to_wstring sto* printf %d %f iostream // #include <string> auto s = std::to_string(201); 10

auto ws = std::to_wstring(233.1000); 4.5 char wchar_t wstring_convert // #include <locale> std::wstring_convert< std::codecvt<wchar_t, char, std::mbstate_t>> cvt(new std::codecvt_byname< wchar_t, char, std::mbstate_t>(" ")); wstring_convert<> cvt codecvt_byname "" std::setlocale std::locale Linux "ja_jp.eucjp" wstring_convert<> std::wstring from_bytes std::string to_bytes std::wstring araragi = cvt.from_bytes( A ); std::wstring tsukihi = cvt.from_bytes(""); std::string koyomi = cvt.to_bytes(l ); std::string aryaryagi = cvt.to_bytes(l""); from_bytes to_bytes 4 11

char wchar_t char const* wchar_t const* const std::string& const std::wstring& char const* first, char const* last wchar_t const* first, wchar_t const* last 4.6 C++ Boost.Regex API std::regex std::wregex std::regex_match 4.6.1 regex_match regex_search regex_match "x(y+)z" // #include <regex> std::regex meruado_kamo(".+@.+"); if (std::regex_match("hoge@example.jp", meruado_kamo)) { std::cout << "\n"; } http://www.din.or.jp/~ohzaki/mail_regex.htm 12

4.6.2 regex_replace regex_replace // #include <regex> std::regex last_part("^(?:.*/)+([^/]*)"); std::string src = "/usr/bin/cc"; std::string replace = "$1"; auto file = std::regex_replace(src, last_part, replace); // file == "cc" 4.7 iostream tm std::put_time std::get_time // #include <ctime> // #include <iomanip> auto time = std::time(nullptr); auto tm = std::localtime(&time); std::cout.imbue(std::locale("")); std::cout << std::put_time(tm, "%c") << std::endl; put_time 2 strftime get_time 4.7.1 Boost Boost.DateTime ptime pt = second_clock::local_time(); std::locale loc(std::locale(""), new time_facet<ptime, char>("%c")); 13

std::cout.imbue(loc); std::cout << pt << std::endl; 5 5.1 Atomic std::atomic Windows Windows long x; InterlockedIncrement(&x); InterlockedDecrement(&x); auto old = InterlockedCompareExchange( &x, newvalue, comparand); std::atomic<int> y; y++; y--; int old = newvalue; bool b = x.compare_exchange_strong(&old, comparand); std::atomic int 5.2 std::async std::launch::async int hoge(std::string const& arg1, int arg2); std::future<int> f = std::async( 14

std::launch::async, hoge, "rofi", 3); int result = f.get(); // std::async(std::launch::async, ) hoge std::future f.get() hoge hoge hoge f.get() std::async 5.3 Boost Boost.Thread std::thread std::async void g(); std::thread th(g, ); th.join(); // 15