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

プログラマーへ64の質問

調べ物をしていたら発見したので思わずやってしまった。 だいぶ前のものだけど…。 関連:プログラマーへ64の質問 0.プログラマは何事も0からスタートするべきだと思いますか? 今まで使ったものがあるなら使いまわそうぜい 1.プログラマの定義は何でしょう…

pstade::oven::any_range

#include <iostream> #include <pstade/oven/any_range.hpp> #include <pstade/oven/filtered.hpp> #include <pstade/oven/transformed.hpp> #include <pstade/oven/io.hpp> #include <boost/lambda/lambda.hpp> template<typename T> pstade::oven::any_range< typename pstade::oven::range_value<T>::type, boost::forwa…</t></typename></boost/lambda/lambda.hpp></pstade/oven/io.hpp></pstade/oven/transformed.hpp></pstade/oven/filtered.hpp></pstade/oven/any_range.hpp></iostream>

pstade::oven::zipped

#include <iostream> #include <boost/tuple/tuple_io.hpp> #include <pstade/oven/zipped.hpp> #include <pstade/oven/copied.hpp> #include <pstade/oven/io.hpp> #include <pstade/oven/identities.hpp> #include <boost/array.hpp> int main(){ namespace oven = pstade::oven; int array1[] = {0, 1, 2, 3, 4}; char a…</boost/array.hpp></pstade/oven/identities.hpp></pstade/oven/io.hpp></pstade/oven/copied.hpp></pstade/oven/zipped.hpp></boost/tuple/tuple_io.hpp></iostream>

pstade::oven::cycled

#include <iostream> #include <string> #include <pstade/oven/cycled.hpp> #include <pstade/oven/io.hpp> int main(){ namespace oven = pstade::oven; namespace lambda = boost::lambda; std::cout << (std::string("01")|oven::cycled(3)) << std::endl; int array[] = {0, 1, 2}; auto range = array|oven::cycled(3…</pstade/oven/io.hpp></pstade/oven/cycled.hpp></string></iostream>

std::string と char[]型の end の位置

std::string と char[] 型で std::end() の返ってくる位置がずれている事に気がついた。 次のコードを実行させるとで実行時エラーが出る。 template<typename T> int distance(const T& range){ return std::end(range) - std::begin(range); } char array[] = "01234"; </typename>…

文字の range を std::string へ代入する

[お題] std::vector の様な文字の range を std::string へ代入したい。 #include <iostream> #include <string> #include <vector> #include <pstade/oven/copied.hpp> #include <pstade/oven/concatenated.hpp> #include <pstade/oven/filtered.hpp> #include <boost/assign.hpp> #include <boost/lambda/lambda.hpp> int main(){ namespa…</boost/lambda/lambda.hpp></boost/assign.hpp></pstade/oven/filtered.hpp></pstade/oven/concatenated.hpp></pstade/oven/copied.hpp></vector></string></iostream>

pstade/oven/io.hpp

[お題] std::vector や int[] を標準出力したい。 #include <iostream> #include <list> #include <pstade/oven/io.hpp> #include <pstade/oven/identities.hpp> #include <pstade/oven/filtered.hpp> #include <pstade/oven/copied.hpp> #include <boost/lambda/lambda.hpp> int main(){ namespace oven = pstade::oven; namespace lam…</boost/lambda/lambda.hpp></pstade/oven/copied.hpp></pstade/oven/filtered.hpp></pstade/oven/identities.hpp></pstade/oven/io.hpp></list></iostream>

7並べ

★概要 プログラムの練習に使用する為のまとめです。 新しい言語を始める時などに使ってもらえればと思います。 アバウトな内容なので分からない部分は適当に脳内で補完して下さい。 ★何で7並べ? 7並べ・・・というかトランプゲームだとイメージしやすく理解が…

pstade::oven::at(n)

#include <assert.h> #include <pstade/oven/at.hpp> int main(){ namespace oven = pstade::oven; int array[] = {0, 1, 2, 3, 4}; assert( (array|oven::at(3)) == array[3] ); return 0; } 内部の動作としては、 *(boost::begin(range)+n); こんな感じ。 std::list の様に要素数でアクセ</pstade/oven/at.hpp></assert.h>…

pstade::oven::copied

#include <vector> #include <list> #include <assert.h> #include <pstade/oven/copied.hpp> int main(){ namespace oven = pstade::oven; namespace lambda = boost::lambda; int array[] = {0, 1, 2, 3, 4}; std::vector<int> array2 = array|oven::copied; std::list<int> array3 = array|oven::copied; assert( boo</int></int></pstade/oven/copied.hpp></assert.h></list></vector>…

pstade::oven::rows(height, width)

#include <iostream> #include <boost/range/algorithm/for_each.hpp> #include <pstade/oven/matrix.hpp> #include <pstade/oven/at.hpp> int main(){ namespace oven = pstade::oven; using oven::at; int array[] = {0, 1, 2, 3, 4, 5, 6, 7}; int array2[2][4] = { {0, 1, 2, 3}, {4, 5, 6, 7}, }; assert( (array|oven…</pstade/oven/at.hpp></pstade/oven/matrix.hpp></boost/range/algorithm/for_each.hpp></iostream>

pstade::oven::concatenated

[お題] 2次元配列を1次元配列の様に走査したい。 #include <iostream> #include <boost/range/algorithm/for_each.hpp> #include <boost/array.hpp> #include <pstade/oven/concatenated.hpp> int main(){ namespace oven = pstade::oven; int array[3][3] = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8} }; boost::for_each(array|oven::concatenated, […</pstade/oven/concatenated.hpp></boost/array.hpp></boost/range/algorithm/for_each.hpp></iostream>

range一覧

pstade::oven を追加しました。 随時更新予定。

pstade::oven::steps

[お題] 配列の要素を1つ飛ばしで取得したい。 #include <iostream> #include <boost/range/algorithm/for_each.hpp> #include <pstade/oven/steps.hpp> int main(){ namespace oven = pstade::oven; int array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; boost::for_each(array|oven::steps(2), [](int n){ std::cout << n << std::endl;</pstade/oven/steps.hpp></boost/range/algorithm/for_each.hpp></iostream>…

BOOST_STATIC_ASSERT(exp)

#include <boost/static_assert.hpp> #include <boost/type_traits/is_void.hpp> template<typename T> struct type_size{ BOOST_STATIC_ASSERT(!boost::is_void<T>::value); // void 以外を受け付ける static const int value = sizeof(T); }; int main(){ BOOST_STATIC_ASSERT(sizeof(int) == 4); BOOST_STATIC_ASSERT(sizeof(sho…</t></typename></boost/type_traits/is_void.hpp></boost/static_assert.hpp>

boost::adaptors::transformed

久々のまともな記事。 boost::adaptors::transformed は、range の値に対して操作を行ないます。 #include <iostream> #include <boost/range/adaptor/transformed.hpp> #include <boost/range/algorithm/for_each.hpp> int to_double(int n){ return n + n; } int main(){ namespace adaptors = boost::adaptors; int array[] = {0, 1, 2, 3, 4};</boost/range/algorithm/for_each.hpp></boost/range/adaptor/transformed.hpp></iostream>…

jam で迷走

昨日からこちらで紹介されていた jam ファイルでライブラリの生成を試そうと四苦八苦しているのだが、なかなかうまくいかない…。 うーん、多分オプションの設定が間違っているとかそんな些細な事だと思うんだが、なぜ、動かないのかがイマイチ分からない。 …

MPLのエラーはややこしい

id:faith_and_braveさんのsub_windowを自分の環境でコンパイルしてみた。 1>------ ビルド開始: プロジェクト: test, 構成: Debug Win32 ------ 1> main.cpp 1>c:\boost\boost_1_44_0\boost\range\iterator.hpp(63): error C2039: 'type' : 'boost::mpl::eva…

boost::function_types::result_type

boost::function_types::result_type は、関数型から戻り値型が取得できる template クラスである。 こんな感じ。 boost::function_types::result_type<int(*)()>::type; // int boost::function_types::result_type<void(*)(int)>::type; // void boost::result_of の処理と似ている</void(*)(int)></int(*)()>…

覚え書き

・boost::function の chain ・boost::program_options ・複数 iterator の取得を行う range ・ファイルコピーツール ・boost を使って簡単なゲーム作成 ・バージョン管理 ・vec ライブラリのリファクタリング ・FPS 周りの処理 ・Graphics/Windows 周りのラ…

BOOST_PP を使用して、複引数の template 関数を自動生成する

[お題] template< typename T0, typename T1 > std::string join_string(const T0& arg0, const T1& arg1){ return boost::lexical_cast<std::string>(arg0) + boost::lexical_cast<std::string>(arg1); } template< typename T0, typename T1, typename T2 > std::string join_string(</std::string></std::string>…

range を for_each 等で走査する時に、次の値が欲しい

こんな感じ。 int array[] = {0, 1, 2, 3, 4, 5}; boost::for_each( boost::combine( array|adaptors::sliced(0, boost::distance(array)-1), array|adaptors::sliced(1, boost::distance(array) ) ), [](boost::tuple<int, int> data){ int n = boost::tuples::get<0></int,>…

BOOST_PP の中身を展開

VisualStudio の場合、/EP オプションを追加するとプリプロセスが展開されて出力されます。 プロジェクトを使用している場合、 [プロジェクトのプロパティ]→[C/C++]→[プリプロセッサ]→[行番号の前処理の抑制] を [いいえ]→[はい(/EP)] に変更します。 #inc…

BOOST_PP_ENUM_SHIFTED(n, def, data)

BOOST_PP_ENUM_SHIFTED(n, def, data) は、 def(z, data, 1), def(z, data, 2) ... def(z, data, n-1) の様に指定した回数分だけマクロの展開を行います。 #include <iostream> #include <boost/preprocessor.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/fusion/include/vector.hpp> #include <boost/assign.hpp> #define N(…</boost/assign.hpp></boost/fusion/include/vector.hpp></boost/range/algorithm/for_each.hpp></boost/preprocessor.hpp></iostream>