
C++11
WIP
1.言語機能(Core Language Features)
【型推論・構文】
auto(型推論)
変数宣言時に使用。変数の初期化子から型を推論。var みたいなもの。イテレータなどを受け取る時に auto にすることで可読性、移植性が良くなる。以前の自動変数指定の auto とは無関係なので注意。
関数の戻り値に使用し、型後置宣言した場合は推論しない。
decltype(式の型取得)
範囲ベースforループ(range-based for: for (auto& x : v))
末尾戻り値構文(trailing return types: auto f() -> int)
関数の戻り値を後置宣言できる。auto とともに使うことが多いが、auto 非推奨な環境では使わないほうが無難。
[C++14 参照] auto f() { return 0; } と書けるのは C++14 から
右辺値参照(rvalue reference: T&&)およびムーブセマンティクス
完全転送(perfect forwarding)
初期化子リスト構文(uniform initialization / list initialization: {})
ラムダ式(lambda expression: capture -> ret { body })
nullptr(型安全なヌルポインタ定数)
NULL(0) からの脱却。明示的に 0 と NULL を区別する。ポインタは 0 初期化ではなく nullptr で初期化すること。
オーバーロードされた関数の引数に int 型とポインタ型が混在する場合、引数 NULL で int 型の関数に飛ばされるなどの面倒な不具合生成を無くすことができる。
【コンパイル時処理・テンプレート】
constexpr(定数式・コンパイル時計算)
static_assert(コンパイル時アサーション)
ユーザー定義リテラル(user-defined literals)
可変引数テンプレート(variadic templates: template<typename... Args>)
エイリアステンプレート(alias templates / using宣言によるtypedef代替)
【クラス・オブジェクト指向】
明示的なデフォルト化・削除関数(= default; / = delete;)
仮想関数修飾子(override / final)
委譲コンストラクタ(delegating constructors)
継承コンストラクタ(inheriting constructors: using Base::Base;)
非静的データメンバ初期化子(in-class member initializers)
スコープ付き列挙型(scoped enums: enum class)および基底型の明示指定
制限のない共用体(unrestricted unions: 非トリビアルなクラスも保持可)
std::string や std::vector のような 非POD 型のオブジェクトを定義できる。共用体自体のコンストラクタやデストラクタは delete される。
AUTOSAR などでは 非POD 型を使用してはいけないルール有り。使用する場合は class にする。
[C++17 参照] POD 表記は非推奨、トリビアルなどの表記が推奨される。また、非トリビアルなオブジェクトを使用する場合、std::variant の使用が推奨される。
拡張フレンド宣言(extended friend declarations)
メンバ関数参照修飾(ref-qualifiers: void f() &;, void f() &&;)
【低レベル・型・環境】
マルチスレッド対応メモリモデル
スレッドローカルストレージ(thread_local)
アライメント制御(alignas / alignof)
属性構文([[attributes]]: [[noreturn]], [[carries_dependency]])
long long int / unsigned long long int(64ビット以上の整数型)
char16_t / char32_t(Unicode文字型)
Unicode文字列リテラル(u8"...", u"...", U"...")
生文字列リテラル(raw string literals: R"(...)")
条件付き例外指定(noexcept演算子 / 指定子)
インライン名前空間(inline namespace)
連続山かっこ構文(Vector<List<int>> の >> を閉じる山かっことして許可)
今までは
std::vector<std::list<int> >のように > を離さないと >> と解釈されてしまっていたが、離さなくて良くなった!不要なエラーがなくなる。
2.新規追加ヘッダ(Standard Library Headers)
<array> - 固定長配列コンテナ
<atomic> - アトミック操作・型
<chrono> - 時間計測・クロック
<condition_variable> - スレッド待機・通知
<forward_list> - 単方向連結リスト
<future> - 非同期処理の結果受取
<initializer_list> - 初期化子リスト受取
<mutex> - 排他制御・ロック機能
<random> - 乱数生成器と確率分布
<ratio> - コンパイル時有理数
<regex> - 正規表現の検索・置換
<scoped_allocator> - ネスト用アロケータ
<system_error> - OSエラーコード管理
<thread> - スレッド生成と管理
<tuple> - 複数型の組コンテナ
<typeindex> - 型情報のインデックス
<type_traits> - コンパイル時型特性
<unordered_map> - ハッシュ連想配列
<unordered_set> - ハッシュ集合コンテナ
[C互換ヘッダ]
<ccomplex> - C互換複素数ヘッダ
<cfenv> - 浮動小数点環境制御
<cinttypes> - 整数型フォーマット
<cstdbool> - C互換ブール型定義
<cstdint> - 固定幅の整数型定義
<ctgmath> - 型総称マクロ互換
<cuchar> - Unicode文字変換機能
3.新規コンテナ・型・クラス(std::)
【コンテナ・データ構造】
std::array(固定長配列)
std::forward_list(単方向連結リスト)
std::unordered_map / std::unordered_multimap(ハッシュテーブル連想配列)
std::unordered_set / std::unordered_multiset(ハッシュテーブル集合)
std::initializer_list(初期化子リストオブジェクト)
【スマートポインタ】
std::unique_ptr(単有権ポインタ)
std::shared_ptr(共有所有権ポインタ)
std::weak_ptr(弱参照ポインタ)
std::default_delete(標準デリータ)
std::enable_shared_from_this(shared_ptr生成インターフェース)
【タプル・関数ラッパー】
std::tuple(多組コンテナ)
std::function(汎用関数オブジェクトラッパー)
std::reference_wrapper(参照ラッパー)
【スレッド・並行処理】
std::thread(スレッド管理)
std::mutex / std::recursive_mutex(排他制御)
std::timed_mutex / std::recursive_timed_mutex(時間制限付き排他制御)
std::lock_guard / std::unique_lock(RAIIロック管理)
std::once_flag / std::call_once(初回一度のみ実行)
std::condition_variable / std::condition_variable_any(条件変数)
std::future / std::shared_future(非同期処理結果受取)
std::promise(非同期処理への値提供)
std::packaged_task(タスクラップ)
std::atomic / std::atomic_flag(アトミック操作)
std::memory_order(メモリアクセス順序付け定数)
【時間・有理数・エラー処理】
std::chrono::duration / std::chrono::time_point(時間長・時点)
std::chrono::system_clock / steady_clock / high_resolution_clock(クロック)
std::ratio(コンパイル時有理数表現)
std::error_code / std::error_condition / std::system_error / std::error_category
【正規表現】
std::basic_regex / std::regex / std::wregex
std::sub_match / std::match_results / std::smatch / std::cmatch
std::regex_iterator / std::regex_token_iterator
【乱数エンジン・分布】
std::default_random_engine / std::mt19937 / std::mt19937_64 / std::minstd_rand 等
std::random_device(非決定論的乱数生成器)
std::uniform_int_distribution / std::uniform_real_distribution
std::bernoulli_distribution / std::binomial_distribution
std::normal_distribution / std::exponential_distribution / std::poisson_distribution 等
4.追加された主要ユーティリティ関数・アルゴリズム(std::)
【汎用操作・ポインタ操作】
std::move(右辺値キャスト)
std::forward(完全転送)
std::move_if_noexcept
std::addressof(オーバーロードに影響されないアドレス取得)
std::declval(未評価文脈でのインスタンス生成)
std::make_shared / std::allocate_shared(shared_ptr生成)
[C++14 参照] std::make_uniqe
std::static_pointer_cast / std::dynamic_pointer_cast / std::const_pointer_cast
【タプル操作・バインド】
std::make_tuple / std::tie / std::forward_as_tuple / std::tuple_cat
std::get (tuple / array / pair)
std::bind
std::placeholders::_1, _2, _3 ...
std::ref / std::cref
【イテレータ・アクセス】
std::begin / std::end(配列およびコンテナ用非メンバ関数)
std::next / std::prev(イテレータ移動)
【文字列・数値変換】
std::to_string / std::to_wstring(数値から文字列)
std::stoi / std::stol / std::stoll(文字列から整数)
std::stoul / std::stoull(文字列から符号なし整数)
std::stof / std::stod / std::stold(文字列から浮動小数点数)
【スレッドユーティリティ】
std::async(非同期実行)
std::lock / std::try_lock(デッドロック回避マルチロック)
std::this_thread::get_id
std::this_thread::yield
std::this_thread::sleep_for / std::this_thread::sleep_until
【アルゴリズム(<algorithm> / <numeric>)】
std::all_of / std::any_of / std::none_of(範囲条件判定)
std::find_if_not(否定条件検索)
std::copy_if / std::copy_n(条件付き・指定個数コピー)
std::move / std::move_backward(範囲ムーブアルゴリズム)
std::shuffle(乱数生成器指定シャッフル)
std::is_partitioned / std::partition_copy / std::partition_point(パーティション操作)
std::is_sorted / std::is_sorted_until(ソート状態判定)
std::is_heap / std::is_heap_until(ヒープ状態判定)
std::minmax / std::minmax_element(最大・最小同時取得)
std::iota(連続値の生成)
【正規表現関数】
std::regex_match(完全一致検証)
std::regex_search(部分一致検索)
std::regex_replace(置換)
5.型特性(Type Traits: <type_traits>)
【型判定】
is_void / is_integral / is_floating_point
is_array / is_pointer / is_reference / is_lvalue_reference / is_rvalue_reference
is_member_object_pointer / is_member_function_pointer
is_enum / is_union / is_class / is_function
is_arithmetic / is_fundamental / is_compound / is_scalar / is_object
is_const / is_volatile / is_trivial / is_trivially_copyable / is_standard_layout
is_pod / is_literal_type / is_empty / is_polymorphic / is_abstract / is_signed / is_unsigned
is_constructible / is_default_constructible / is_copy_constructible / is_move_constructible
is_assignable / is_copy_assignable / is_move_assignable / is_destructible
is_nothrow_constructible / is_nothrow_default_constructible 等(各種例外送出判定)
is_trivially_constructible / is_trivially_copyable 等(各種トリビアル判定)
【型関係】
is_same(型の完全一致)
is_base_of(派生・基底関係)
is_convertible(暗黙的型変換の可否)
【型変換・操作】
remove_cv / remove_const / remove_volatile / add_cv / add_const / add_volatile
remove_reference / add_lvalue_reference / add_rvalue_reference
remove_pointer / add_pointer
make_signed / make_unsigned
remove_extent / remove_all_extents
aligned_storage / aligned_union
decay(配列・関数のポインタ化およびcv修飾除去)
enable_if(SFINAE制御)
conditional(コンパイル時条件分岐)
common_type(共通型導出)
underlying_type(enum基底型取得)
result_of(関数呼び出し戻り値型取得)
6.既存コンテナへ一括追加されたメンバ関数
emplace / emplace_back / emplace_front / emplace_hint(要素のインプレース構築)
cbegin / cend / crbegin / crend(const_iterator取得)
shrink_to_fit(不要なキャパシティの破棄)
data(連続バッファポインタの取得: vector, basic_string)
ムーブコンストラクタ・ムーブ代入演算子(全コンテナ)
initializer_list を受け取るコンストラクタおよび代入演算子(全コンテナ)
参照:
#C #cpp #cpp11 #programming #tutorial #modern #study #STL #std #lib