備忘録

プログラムやゲーム関連に関すること

2014-09-03から1日間の記事一覧

【C++】否定を実行する関数オブジェクト

int 値の否定 int n = 1; std::cout << std::negate<int>()(n) << std::endl; // -1 int i[] = {1, -2, 3, -4}; std::transform(std::begin(i), std::end(i), i, std::negate<int>()); std::for_each(std::begin(i), std::end(i), [](int x){ std::cout << x << std::e</int></int>…

【C++】スマートポインタ補助関数

make_shared【C++11】 オブジェクトと管理用データを一緒に連続領域に new するので効率的 make_unique【C++14】 名前の一貫性、new の記述が不要になる 例 shared_ptr<T> sp = make_shared<T>(); unique_ptr<T> up = make_unique<T>(); unique_ptr はポインタをコピーし</t></t></t></t>…

【C++】ヌルポインタ

NULL【C++98】 #define NULL 0 と定義される、単なる数値の0 nullptr【C++11】 あらゆるポインタ型のヌルポインタを表すポインタ定数のキーワード 整数には変換できない 例 void f(int n); void f(const char *s); f(0); // f(int) f("hello"); // f(const …

【C++】ラムダ式

C++ における関数オブジェクト struct PlusOne { auto operator() (int x) const -> int { return x + 1; } }; PlusOne plusOne = {}; std::cout << plusOne(0) << std::endl; // 1 ラムダ式の値は、匿名の関数オブジェクトである auto lambda_0 = [](int x)…

【C++】 C++ の新しい typedef 方法

Before typedef int type1; typedef int type2[10]; typedef type1 (*type3)(type2); After using type1 = int; using type2 = int[10]; using type3 = type1 (*)(type2); 引用:本の虫: C++の新しいtypedef方法、alias declaration