2011-01-01から1ヶ月間の記事一覧
あると便利だと思うのですが、C++0xにはありません。 #include <type_traits> // and template <class ...Fs> struct and_ : std::true_type {}; template <class F1, class ...Fs> struct and_<F1, Fs...> : std::conditional<F1::value, and_<Fs...>, std::false_type>::type {}; // or template <class ...Fs> struct or_ : std::false_type {}…</class></f1::value,></f1,></class></class></type_traits>
C++0xのは型に関する情報を取得する重要なライブラリで、GCC4やVC10でも実装が提供されています。しかしそのうちのtype propertiesに関しては、N3225で大幅に変更されたこともあり、未実装の部分が多く残っています。 そこで、GCC4.6.0(20110122)を使い、未…
switch case で文字列を使う - とくにあぶなくないRiSKのブログ ハッシュ関数としてCRC-CCITTを実装してみました。 #include <cstdint> #include <iostream> #include <string> namespace crc_ccitt { constexpr unsigned int process_char(unsigned int acc, int n) { return n > 0 ? p</string></iostream></cstdint>…
rangeを一定サイズの部分rangeに分割するadaptorを書いてみました。こんな感じに使えます。 #include <iostream> #include <boost/lambda/lambda.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/as_literal.hpp> #include "chunked.hpp" int main() { boost::for_each( // 文字列を4文字ごとに分割する boost::as_literal("Hello, wor</boost/range/as_literal.hpp></boost/range/algorithm/for_each.hpp></boost/lambda/lambda.hpp></iostream>…