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

boost::function で Loki Chain のような処理

ここまでは考えた。 #include <iostream> #include <boost/function.hpp> #include <boost/functional.hpp> #include <boost/function_types/result_type.hpp> #include <boost/bind.hpp> #include <boost/utility/result_of.hpp> #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp> // boost::b…</boost/fusion/include/at_c.hpp></boost/fusion/include/vector.hpp></boost/utility/result_of.hpp></boost/bind.hpp></boost/function_types/result_type.hpp></boost/functional.hpp></boost/function.hpp></iostream>

boost::bind

boost::function の引数を自由に設定することが出来る。 #include <boost/function.hpp> #include <boost/functional.hpp> #include <boost/bind.hpp> int division(int n, int m){ return n / m; } int main(){ // あらかじめ引数を設定することが出来る boost::function<int()> div_6_3 = boost::bind(division, 6, 3); asser</int()></boost/bind.hpp></boost/functional.hpp></boost/function.hpp>…

boost::function

関数の保持を行うライブラリ。 #include <iostream> #include <assert.h> #include <boost/function.hpp> #include <boost/functional.hpp> #include <boost/bind.hpp> int division(int n, int m){ return n / m; } template<typename T> bool is_equal(const T& lhs, const T& rhs){ return lhs == rhs; } struct game{ void even1(int …</typename></boost/bind.hpp></boost/functional.hpp></boost/function.hpp></assert.h></iostream>

boost::polygon::point_data ⇔ D3DXVECTOR2 続き

前回の続き。 geometry_concept、point_traits、point_mutable_traits の3つのクラスを特殊化すれば互換性の壁をぶっ壊せるらしい。 #include <assert.h> #include <d3dx9.h> #include <boost/polygon/polygon.hpp> #include <boost/array.hpp> #include <pstade/oven/copied.hpp> namespace boost{ namespace polygon{ // D3DXVECTOR2 を boost::poly</pstade/oven/copied.hpp></boost/array.hpp></boost/polygon/polygon.hpp></d3dx9.h></assert.h>…

boost::asio

ネットワーク通信を簡易に行えるすごいライブラリ。 中の人がネットワークについてさっぱり理解していないので、これぐらいの認識です。 #include <iostream> #include <boost/asio.hpp> #include <boost/range/algorithm/for_each.hpp> #include <pstade/oven/stream_lines.hpp> int main(){ namespace asio = boost::asio; namespace oven = pstade::oven</pstade/oven/stream_lines.hpp></boost/range/algorithm/for_each.hpp></boost/asio.hpp></iostream>…

boost::polygon::point_3d_data と D3DXVECTOR3 の変換

Boost.Polygonの謎 id:nagoya313:20100921 こんな感じ? #include <iostream> #include <d3dx9.h> #include <boost/polygon/polygon.hpp> #include <boost/array.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/adaptor/transformed.hpp> #include <pstade/oven/copied.hpp> typedef boost::polygon::p…</pstade/oven/copied.hpp></boost/range/adaptor/transformed.hpp></boost/range/algorithm/for_each.hpp></boost/array.hpp></boost/polygon/polygon.hpp></d3dx9.h></iostream>

pstade::oven::copied

連続した数値の配列の初期化の続き。 namespace oven = pstade::oven; std::vector<int> array = boost::irange(0, 10)|oven::copied; boost::for_each(array, [](int n){ std::cout << n; }); 出力 0123456789 こっちの方がスマート! コメントありがとうござい</int>…

boost::irange

基本的な使い方は、boost::counting_range と同じ。 違う点は、ステップの設定ができる。 boost::irange(0, 5); // {0, 1, 2, 3, 4} bosst::irange(0, 10); // {0, 2, 4, 6, 8} ただし、ここで注意する点がある。 boost::for_each(boost::irange(0, 9, 2), […

連続した数値の配列の初期化

C++

こんなことがしたい。 array = [1..10] こうですか、分かりません>< template<typename T> std::vector<T> make_counting(const T& first, const T& last){ std::vector<T> result(last - first); boost::copy(boost::irange(first, last), result.begin()); return result; </t></t></typename>…

ラムダは便利だな

今までスコープの外の変数を使う場合は、BOOST_FOREACH を使っていたんですが、 int sum = 0; BOOST_FOREACH(int n, boost::counting_range(0, 10)){ sum += n; } [&]にすればスコープの外をキャプチャ出来るんですね。 int sum = 0; boost::for_each(boost:…

テキストファイル内で使われている文字を数える 続き

昨日の続き。 ワイド文字版。 #include <iostream> #include <map> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/adaptor/sliced.hpp> #include <boost/range/as_array.hpp> #include <pstade/oven/file_range.hpp> int main(){ namespace oven = pstade::oven; namespace adaptors = boost::adaptors; auto fr…</pstade/oven/file_range.hpp></boost/range/as_array.hpp></boost/range/adaptor/sliced.hpp></boost/range/algorithm/for_each.hpp></map></iostream>

テキストファイル内で使われている文字を数える

range の練習問題 #include <iostream> #include <boost/range/algorithm/count.hpp> #include <boost/range/counting_range.hpp> #include <pstade/oven/file_range.hpp> int main(){ namespace oven = pstade::oven; auto frange = oven::file_range<char>("BOOST_LICENSE_1_0.txt"); BOOST_FOREACH(char key, boost::counting…</char></pstade/oven/file_range.hpp></boost/range/counting_range.hpp></boost/range/algorithm/count.hpp></iostream>

pstade::oven::stream_lines

\(^o^)/ #include <iostream> #include <fstream> #include <string> #include <boost/range/algorithm/for_each.hpp> #include <pstade/oven/stream_lines.hpp> int main(){ namespace oven = pstade::oven; std::ifstream ifs("test.txt"); boost::for_each(oven::stream_lines(ifs), [](std::string line){ std::cout <<…</pstade/oven/stream_lines.hpp></boost/range/algorithm/for_each.hpp></string></fstream></iostream>

std::ifstream の range

テキストファイルの行単位での範囲を取得するとかそんな感じ。 #include <iostream> #include <fstream> #include <string> #define BOOST_FILESYSTEM_VERSION 3 #include <boost/range.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/lexical_cast.hpp>…</boost/lexical_cast.hpp></boost/range/algorithm/for_each.hpp></boost/filesystem/fstream.hpp></boost/filesystem.hpp></boost/range.hpp></string></fstream></iostream>

boost::filesystem

#include <iostream> #define BOOST_FILESYSTEM_VERSION 3 // filesystem で日本語を使用する場合に定義 #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/range/algorithm/for_each.hpp> int main(){ namespace fs = boost::filesystem; // カレントディレクトリのファイルを列挙 auto dir_range = std::make_pai…</boost/range/algorithm/for_each.hpp></boost/filesystem/fstream.hpp></boost/filesystem.hpp></iostream>

つまりどういう事だってばよ…

directory_all_range(fs::current_path())|oven::sorted で実行時に吹っ飛ぶ oven::any_range を2回ループでイテレータが飛ぶ boost::single_pass_traversal_tag があ や し い any_range だと問題ない any_range だと2回以上のループで死亡 forward_travers…

boost::filesystem を使ってディレクトリ直下の全てのディレクトリ・ファイルを列挙

#define BOOST_FILESYSTEM_VERSION 3 // filesystem で日本語を使用する場合に定義 #include <iostream> #include <boost/filesystem.hpp> #include <boost/range.hpp> #include <boost/range/adaptors.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/join.hpp> #include <pstade/oven/any_range.hpp> // ディレ…</pstade/oven/any_range.hpp></boost/range/join.hpp></boost/range/algorithm/for_each.hpp></boost/range/adaptors.hpp></boost/range.hpp></boost/filesystem.hpp></iostream>

range の結合

boost::range には見当たりませんでしたが pstade::oven にありました。 boost にもあると速攻でツッコミを受けました。 boost::adaptros ばっかり見てて気がつかなかった…。 コメントありがとうございます。 #include <iostream> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/join.hpp> #include <pstade/oven/jointed.hpp> int m</pstade/oven/jointed.hpp></boost/range/join.hpp></boost/range/algorithm/for_each.hpp></iostream>…

OpenCV

とりあえず、ピクセルの走査だけやってみた。 #include <iostream> #include <string> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/counting_range.hpp> #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/make_fused.hpp> #include <boost/fusion/include/make_vector.hpp> #include </boost/fusion/include/make_vector.hpp></boost/fusion/include/make_fused.hpp></boost/fusion/include/vector.hpp></boost/range/counting_range.hpp></boost/range/algorithm/for_each.hpp></string></iostream>

boost::range

range と言うことでデータを範囲として扱うライブラリです。 配列の始点と終点の位置を使用して、データに対し操作を行ないます。 配列の std::begin() と std::end() を保持しているクラスがあるってイメージだと分かりやすいかな? まぁ説明すると怪しくな…

Google Analytics

以前、アクセス数が分からないと記事を書いたが、 1週間ぐらい前に、Google Analyticsを導入してみた。 アクセス数だけじゃなくて、平均サイト滞在時間や検索ワードなんかも調べてくれるのでなかなか面白い。 アクセス元のPC環境も分かるし、すごいなこれ。 …

boost::iterator_adaptor

イテレータについて調べていたら、boost::iterator_adaptor を使用して、 簡単にイテレータを作れるみたいなのでやってみました。 #include <iostream> #include <boost/iterator_adaptors.hpp> #include <boost/range/algorithm/for_each.hpp> #include <boost/range/adaptor/transformed.hpp> struct vec{ struct iterator : public boost::iterator_adaptor< iterator, fl…</boost/range/adaptor/transformed.hpp></boost/range/algorithm/for_each.hpp></boost/iterator_adaptors.hpp></iostream>

ワイド文字列

ワイド文字列について理解していなかったので個人的なまとめ。 //wchar_t wstr[] = "日本語"; // const char [11]' から 'wchar_t []' に変換出来ない wchar_t wstr[] = L"日本語"; // ワイド文字列の先頭に L をつける std::wcout.imbue(std::locale("japan…

状態遷移の管理人

昨日もチラッと書いたけど各ゲームの状態遷移(シーン)を boost::msm で管理するのと スクリプトで状態を管理するのを比べると一長一短だと思った。 boost::msm だと全体を通しての管理がすごく楽なんだけど 動的に状態を変更したり追加できないのが難点。 …

boost::msm

昨日の続きです。 実際にステートチャート図を書きながらやってみました。 #include <iostream> #include <boost/msm/back/state_machine.hpp> #include <boost/msm/front/state_machine_def.hpp> namespace msm = boost::msm; namespace mpl = boost::mpl; // 状態 namespace states{ struct opening : public msm::front::state<>{}; struct men</boost/msm/front/state_machine_def.hpp></boost/msm/back/state_machine.hpp></iostream>…

Meta State Machine

id:faith_and_braveさんの『Boostライブラリ一周の旅』で紹介されていた Meta State Machine が面白そうなのでやってみたんだけど難しい。 いかんせん、概要が理解できていないので、 『状態遷移のテーブルを定義しておいて、切り替え時に任意の処理が呼ばれ…

boost::fusion::for_each

以前エントリした『boost::tuple で for_each のような処理』で、 id:gintenlaboさんから 「boost::fusion で出来るよ」 と、コメントを頂いたのでやってみました。 #include <string> #include <boost/fusion/include/vector.hpp> struct print_impl{ template<typename T> void operator ()(const T& rhs) const{</typename></boost/fusion/include/vector.hpp></string>…

待ち処理 続き

前回の記事を書いた後に、 「ミリ秒未満の端数分だけ、while ループで待ち処理すればいいんじゃね?」 と、思い改良しました。 使い勝手は前回と変わらず。 #include <boost/chrono.hpp> #include <boost/chrono/timer.hpp> #include <boost/utility/enable_if.hpp> #include <Windows.h> #include "sleep.hpp" #include <iostream> int main(){ using kmt_</iostream></windows.h></boost/utility/enable_if.hpp></boost/chrono/timer.hpp></boost/chrono.hpp>…

待ち処理

WINAPI の Sleep() に chrono::duration で定義されている単位で渡したかったのでラップしました。 ついでにミリ秒未満なら while ループで待ち処理も実装。 #include <boost/chrono.hpp> #include <boost/chrono/timer.hpp> #include <boost/utility/enable_if.hpp> #include <Windows.h> #include "sleep.hpp" int main(){ using kmt_ex::sleep</windows.h></boost/utility/enable_if.hpp></boost/chrono/timer.hpp></boost/chrono.hpp>…

ヘッダーに情報を掲載

boost 関連の記事のエントリを一覧を作ってヘッダーにリンクを張ってみた。 vec の方もそのうち作るつもり。 しかし、レイアウトがしょっぱいのでなんとかしたい。 とりあえず、一旦この形で参考になりそうなサイトがあれば そのレイアウトをパクる予定。