2011-10-20から1日間の記事一覧

constexpr の再帰上限数

C++

512 回以上であることが推奨されています.GCC 4.6.1 ではデフォルトで 512 回です. repeated.cpp // apply f n times to x template <class F, class T> constexpr T repeated(F f, unsigned n, T x) { return n == 0 ? x : repeated(f, n - 1, f(x)); } constexpr int inc(i</class>…

コンテナの要素を別のコンテナに移動する

C++

コンテナごとムーブ std::vector<T> v1; // ... std::vector<T> const v2(std::move(v1)); move_iterator を使ってムーブ std::vector<T> v; // ... std::list<T> const l( std::make_move_iterator(v.begin()), std::make_move_iterator(v.end())); move アルゴリズムを</t></t></t></t>…