Boost

Boost.PtrContainer

Boost.PtrContainerのptr_array<>というのを使ってみました. 中身をポインタとして保持して,アクセスする時はポインタの先の参照を返してくれる粋なやつです. ptr_array<>はptr_vector<>とかに比べてちょっと特殊かも. 実体の供給方法とかnullの保持とか…

PropertyTreeのptreeをiterationする

ちょっと調べたのでメモです.以下の様なiniファイルのKeywordsを順番にiterationしていくのが目的です.// trends.ini [Keywords] 触手 = 秋猫 しまぱん = 桜花 縞ぱん = 桜花 縞パン = 桜花 #include <iostream> #include <boost/property_tree/ini_parser.hpp> namespace ptl = boost::property_tree; in</boost/property_tree/ini_parser.hpp></iostream>…

普通のBoostプログラミング

この記事はC++ Advent Calendar jp 2010 : ATNDの7日目の記事です. 他の記事と比べちゃダメです. わたしはほんわか担当なので. テーマは(自分の力量制限により)「普通のBoostプログラミング」です. 最近Boostを使ったコード片の比較的つまらなくなさそ…

Boost.MultiArrayでresize()やview()がコンパイルできない件

1つ前の記事(と言っても11ヶ月前のですがw)の解決方法です. いえ,解決自体はもっと前にしてたのですがメモをしていなかったので.参考: compiler bug in msvc10 with std::copy _HAS_ITERATOR_DEBUGGING | Microsoft Docs これによると,MSVC2010のstd…

VS2010でMultiArray::resize()が使えない?

VS2010 beta2で次のコードがコンパイルエラーになります. VS2008 EEだと通るんですけどね. #include <boost/multi_array.hpp> int main(){ boost::multi_array<int, 2> ary(boost::extents[1][2]); ary.resize(boost::extents[2][3]); } error C2665: 'std::_Copy' : none of the 2 overlo</int,></boost/multi_array.hpp>…

セマフォ

Boost.Threadにセマフォが無いのでどうしようかと思いましたが,Boost.Interprocessにあるんですね. 単純にそれを使ってみました. 超シンプルです. #include <cstddef> #include <iostream> #include <boost/thread/thread.hpp> #include <boost/interprocess/sync/named_semaphore.hpp> const std::size_t create_threads_number = 5; const std::si</boost/interprocess/sync/named_semaphore.hpp></boost/thread/thread.hpp></iostream></cstddef>…

chset

#include <boost/spirit.hpp> using namespace boost::spirit; struct Grammar : grammar<Grammar> { std::vector<std::string>& strs; // 略 template<typename ST> struct definition { typedef rule<ST> rule_t; rule_t bad; rule_t good; definition(const Grammar& self){ bad = chset<>("abcde")[push_back_a(sel</st></typename></std::string></grammar></boost/spirit.hpp>…

for_p

for_pの使い方が全然分からん.ぐぐってもサンプルプログラムとか出てこない.ていうか,ネット上で扱われてる気がしないんだけど…. uint_p[for_p(eps_p, eps_p, eps_p)[eps_p] ] これが通らないとは…. …あれ? #http://www.boost.org/doc/libs/1_35_0/lib…

push_back_aが誤動作?

boost::spirit::push_back_a(dst, val)が正常に動いていないような気がします. #include <boost/spirit.hpp> #include <boost/lambda/bind.hpp> #include <iostream> #include <string> #include <vector> struct TestGrammar : boost::spirit::grammar<TestGrammar> { std::vector<int>& ret; TestGrammar(std::vector<int>& ref): ret(ref){…</int></int></testgrammar></vector></string></iostream></boost/lambda/bind.hpp></boost/spirit.hpp>

うわー

うわー.原因分かったー. hex_p1個でいいのに2個も書いてた.action付けてたせいでごっちゃになってた….

あれれ

carriage returnちゃんとcntrl_pで反応するじゃないか.んー,別のところが原因か.

あれ

carriage returnじゃなかったwww しかもcrはcntrl_pだと反応しない. 別のやってみよう.

\r + BOM

Boost.Spiritで,コマンドラインでデータを渡すとうまくいくのに,ファイルから読んでデータを渡すとうまくいかない. きっとこれはwindowsのせいだ! などと勝手に決め込んで調査したらそうでしたw先頭にBOM,最後にキャリッジリターンがありました.両方b…

これだ!

Boost.Spiritを使おう!

だめだー.

MSVC7.xだと*_oarchiveにSTLをつっこめない. ちなみにfedoraだと同じコードで動いています.まぁ実行時エラーだからコンパイル通ってるんだけどね. やっぱりMSVC7.xはもう古いのか.こっちではこの機能を使うのはあきらめよ.

相性?

なんか #include の前に #include // d3d9.hでも があるとダメなようです. ていうかそうです. ちなみに #include の方が先に書いてあれば問題ないです.他のヘッダファイルに影響を及ぼすなんて,ダメな子だなぁ.ぁ,DirectX SDK November 2007です. ヘ…

binary_iarchive

boostのバージョンを1_35にあげました. msvc7.xで#include とすると大量のバグが…www んー,boostのインストールに失敗したのか,msvcが悪いのか…. 調べてみます.

暗号化

Boost.Serializationでserializeしたバイナリデータを,暗号化.…は略したけど,バイナリデータに対してBoost.Serializationを呼ぶ. バイナリデータを扱うときはfopenとか使わなきゃならないんだよね.std::fstreamとか使うと色々整形されたりしてうまく扱…

std::merge

コンテナへのイテレータが入ったコンテナをマージする.std::vector<>へのconst_iteratorが入ったstd::vector<>をstd::mergeする. なんか必要になったんで. 今回はintです. #include <algorithm> #include <functional> #include <iostream> #include <iterator> #include <vector> #include <boost/bind.hpp> // 参照先を返す</boost/bind.hpp></vector></iterator></iostream></functional></algorithm>…

前のやつできました.

これの下のバージョンができました. http://d.hatena.ne.jp/graighle/20080511/1210536299 #include <iostream> #include <map> #include <vector> #include <algorithm> #include <boost/bind.hpp> // イテレータの指す先を返す template<class IT> struct unref : std::unary_funtion<IT, typename std::iterator_traits<IT>::value_type> { const typ…</it,></class></boost/bind.hpp></algorithm></vector></map></iostream>

if_

以下のことをやりたいのですが,できません. というか寝ますので今日やったことをまとめてみただけです. ちなみに今日は12時間程MHFをやっていましたwww 多分明日はやらないかなぁ. #include <algorithm> #include <map> #include <boost/lambda/bind.hpp> #include <boost/lambda/if.hpp> namespace bll = boost::l</boost/lambda/if.hpp></boost/lambda/bind.hpp></map></algorithm>…

できたーww

一つ目はできたーw #include <iostream> #include <map> #include <vector> #include <algorithm> #include <boost/bind.hpp> struct test { void show(int x) const{ std::cout << x << std::endl; } }; int main(){ typedef std::map<int, object> my_map; typedef my_map::value_type my_pair; std::map<int, test> m; // まぁこの例</int,></int,></boost/bind.hpp></algorithm></vector></map></iostream>…

これをやりたいw

以下のをやりたいけど,できんw #include <iostream> #include <map> #include <vector> #include <algorithm> #include <boost/bind.hpp> struct test { void show(int x) const{ std::cout << x << std::endl; } }; int main(){ std::map<int, test> m; // まぁこの例だとstd::mapの意味はないですがw m[0] = test(); m</int,></boost/bind.hpp></algorithm></vector></map></iostream>…

boost::bindすげーw

Boost.Bindすげーw これは感動するwww

fcpp

なんかコンパイルエラーになります. #define BOOST_FCPP_ENABLE_LAMBDA // これのせい #include <boost/fcpp/fcpp.hpp> int main(){ return 0; } boost/fcpp/lambda.hpp:614: error: declaration of ?typedef typename OrigET::Go::BE boost::fcpp::lambda_impl::exp::BindingEnv</boost/fcpp/fcpp.hpp>…

cast

便利なもの発見. #include <iostream> #include <string> #include <boost/lexical_cast.hpp> int main(){ std::string str = "3.14"; double pi = 0.0; try { pi = boost::lexical_cast<double>(str); } catch(const boost::bad_lexical_cast&){ std::cerr << "cast failed" << std::endl; return 1; } std::c</double></boost/lexical_cast.hpp></string></iostream>…

基本的な流れは解ってきた

Boost.Asioの基本的な流れは解ってきました.tutorialとかものすごい複雑になってますが,基本的な動作は非常に簡単な模様. ぎゃー,ソースコードの色付け機能があったんだw今まで(短い間だったけど)fontタグで囲んで一個一個色つけてたw Boost.Asioも…

boost::smart_ptr<Base> ptr(new Derived);

見出し.ホントは半角にしたかった. 何か投稿しようとしたらメンテとか言って記事消されたwこのエントリ書くの二回目. #include <boost/shared_ptr.hpp> struct Base { ~Base() throw(){} // NOT virtual }; struct Derived : Base { ~Derived() throw(){} }; int main(){ boost</boost/shared_ptr.hpp>…

fedora8でboost

昨日とは別にfedora8にも入れました.そしたらboost::iostream(s)のビルドができない. ビルドエラーが起きてるファイル名が iostreams/src/zlib.cpp iostreams/src/bzip2.cpp のような感じだったのでzlibとbzip2を入れたら普通にできた. Boost::Asioの前に…

Boost C++ Libraries プログラミング第二版

ぉー.Boost C++ Libraries プログラミング第二版の載ってるじゃないか.Boost.Iostreams Boost.Asio他にも沢山載ってたー. Boost.FilesystemとBoost.Threadが載ってるから買ったんだけど,いい買い物したw これを買ったのは今年の初詣に行った日で,初詣…