2011-10-01から1ヶ月間の記事一覧

random_shuffled range アダプタ

久しぶりに range アダプタでも. 考え方は oven::sorted と同じで,range からイテレータのリストを作り,そのリストをシャッフルします.結果として forward range にも対応できます. random_shuffled.hpp (要 P-Stade) #ifndef IORATE_RANDOM_SHUFFLED_H…

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>…

C++ で FibBuzz

震源地: Codnote.net やりましょう. fibbuzz.cpp #if !defined(BOOST_PP_IS_ITERATING) #include <boost/preprocessor/iteration/iterate.hpp> #include <boost/preprocessor/slot/slot.hpp> #define BOOST_PP_VALUE 1 #include BOOST_PP_ASSIGN_SLOT(1) #define BOOST_PP_VALUE 1 #include BOOST_PP_ASSIGN_SLOT(2) #define BOOST_P…</boost/preprocessor/slot/slot.hpp></boost/preprocessor/iteration/iterate.hpp>