Top/Lang/C++/C++11

目次

C++11 のキーワード (取り敢えず関心のあるものだけ)

スコープ付き enum

enum class COMMAND {
    IDLE,
    START,
    STOP,
};

int foo()
{
    COMMAND cmd = COMMAND::IDLE;   // スコープ付きで定義した enum 値は、スコープが必要になる。
    ...
}

enum の基礎型の指定

for 文(範囲指定)

for_each

#include <vector>     // for std::vector
#include <algorithm>  // for std::for_each

std::vector<int> v = { 1, 2, 3, 4 };
std::for_each( v.begin(), v.end(), [](int& n) { m *= 5; } );

右辺値参照とムーブセマンティクス (move semantics)

一時オブジェクト

std::move() 関数

ムーブコンストラクタとムーブ代入演算子

アライメントの指定

std::nullptr

参照修飾子

移譲/継承 コンストラクタ

explicit な型変換演算子

ラムダ式

[キャプチャ] (仮引数リスト) -> 戻り値の型 { 関数の中身 };

属性

例外

例外クラスの使い分け

例外を送出しないことを明示する

例外ポインタ

入れ子の例外関連

std::sto* --- 文字列を数値に変換する

int std::stoi( const string& str, size_t* idx = 0, int base = 10 );
int std::stoi( const wstring& str, size_t* idx = 0, int base = 10 );
long std::stol( const string& str, size_t* idx = 0, int base = 10 );
long std::stol( const wstring&  str, size_t* idx = 0, int base = 10 );
unsigned long std::stoul( const string& str, size_t* idx = 0, int base = 10 );
unsigned long std::stoul( const wstring& str, size_t* idx = 0, int base = 10 );
long long std::stoll( const string& str, size_t* idx = 0, int base = 10 );
long long std::stoll( const wstring& str, size_t* idx = 0, int base = 10 );
unsigned long long std::stoull( const string& str, size_t* idx = 0, int base = 10 );
unsigned long long std::stoull( const wstring& str, size_t* idx = 0, int base = 10 );
float std::stof( const string& str, size_t* idx = 0 );
float std::stof( const wstring& str, size_t* idx = 0 );
double std::stod( const string& str, size_t* idx = 0 );
double std::stod( const wstring& str, size_t* idx = 0 );
long double std::stold( const string& str, size_t* idx = 0 );
long double std::stold( const wstring& str, size_t* idx = 0 );

std::to_string --- 数値を文字列に変換する

#include <string>

std::string std::to_string( int val );
std::string std::to_string( unsigned int val );
std::string std::to_string( long val );
std::string std::to_string( unsigned long val );
std::string std::to_string( long long val );
std::string std::to_string( unsigned long long val );
std::string std::to_string( float val );
std::string std::to_string( double val );
std::string std::to_string( long double val );

std::wstring std::to_wstring( int val );
std::wstring std::to_wstring( unsigned int val );
std::wstring std::to_wstring( long val );
std::wstring std::to_wstring( unsigned long val );
std::wstring std::to_wstring( long long val );
std::wstring std::to_wstring( unsigned long long val );
std::wstring std::to_wstring( float val );
std::wstring std::to_wstring( double val );
std::wstring std::to_wstring( long double val );

正規表現での検索

浮動小数点数の入力

日付・時刻

乱数生成

shared_ptr (共有ポインタ)

リソース開放時の処理の指定

std::shared_ptr::get() --- 組み込みポインタの取得

std::shared_ptr<ClassA>    up_a1;
ClassA  *p_a1 = up_a1.get();     // up_a1 が持っている ClassA のリソースを指す組み込みポインタを取得

std::make_shared() --- std::shared_ptr 構築のためのヘルパ関数

decltype

auto 型

auto 型の利点

unique_ptr

std::move() --- unique_ptr の移動

std::unique_ptr::get() --- 組み込みポインタの取得

std::unique_ptr<ClassX>    up_x1;
ClassX  *p_x1 = up_x1.get();     // up_x1 が持っている ClassX のリソースを指す組み込みポインタを取得

複数の値から、最大値または最小値を選択する

2つの変数を入れ替える

コンパイル時にアサーションを行う

浮動小数点数の四捨五入

数学関数

std::function --- 関数オブジェクトを変数に持つ

時間演算を行う

タプル

constexpr

static_assert

システム終了

スレッド

コンテナ

build (clang++/g++)


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-15 (水) 23:58:17