boost

BOOST_TYPE_ERASURE_MEMBER で const なメンバ関数の呼び出し方

以前、『BOOST_TYPE_ERASURE_MEMBER では const なメンバ関数が呼び出せない』という記事を書いたのですが定義が間違っていました。 下記のように _self const を記述する事で const なメンバ関数も問題なく処理することが出来ました。 [ソース] #include <boost/type_erasure/any.hpp> #</boost/type_erasure/any.hpp>…

Boost 1.51.0 がリリース

Boost 1.51.0 がリリースされました。 Version 1.51.0 Boost 1.51.0 リリースノート(日本語版) Boost 1.51.0 では Boost.Context が追加されました。 ぼちぼち触ってみたいところ。

BOOST_TYPE_ERASURE_MEMBER では const なメンバ関数が呼び出せない

[追記] 嘘です。 const なメンバ関数も呼び出すことが出きました。 BOOST_TYPE_ERASURE_MEMBER で const なメンバ関数の呼び出し方 BOOST_TYPE_ERASURE_MEMBER では、オブジェクトが const だった場合に const なメンバ関数が正しく呼び出せません。 どうい…

Boost.TypeErasure でタスク処理

C++ タスク処理といえば、継承を使用した多態性で実装するのが一般的(だと思う)のですが、Boost.TypeErasure でちょっと実装してみました。 [ソース] #include <boost/type_erasure/builtin.hpp> #include <boost/type_erasure/operators.hpp> #include <boost/type_erasure/iterator.hpp> #include <boost/type_erasure/callable.hpp> #include <boost/type_erasure/any.hpp> #inclu…</boost/type_erasure/any.hpp></boost/type_erasure/callable.hpp></boost/type_erasure/iterator.hpp></boost/type_erasure/operators.hpp></boost/type_erasure/builtin.hpp>

Boost.TypeErasure でメンバ変数っぽいのを定義する

基本的に Boost.TypeErasure ではメンバ関数を介してしか、元の型へアクセス出来ないんですが、operator T とか使ってメンバ変数でアクセスしようとするとこんな感じに。 [ソース] #include <boost/type_erasure/any.hpp> #include <boost/type_erasure/any_cast.hpp> #include <boost/type_erasure/builtin.hpp> #include <boost/type_erasure/operators.hpp> #include <iostream> #include </iostream></boost/type_erasure/operators.hpp></boost/type_erasure/builtin.hpp></boost/type_erasure/any_cast.hpp></boost/type_erasure/any.hpp>

BOOST_TYPE_ERASURE_MEMBER

Boost.TypeErasure に BOOST_TYPE_ERASURE_MEMBER というマクロが用意されており、これを使用すれば簡単に Concept を定義出来ます。 使い方はこんな感じ。 [ソース] #include <boost/type_erasure/any.hpp> #include <boost/type_erasure/member.hpp> #include <boost/mpl/vector.hpp> #include <boost/range/algorithm/for_each.hpp> #include <vector> BOOST_TYPE_ERASURE…</vector></boost/range/algorithm/for_each.hpp></boost/mpl/vector.hpp></boost/type_erasure/member.hpp></boost/type_erasure/any.hpp>

Boost.1.50.0 で がコンパイルエラーになる

Boost 1.5.0 の が gcc(clang) + std=c++0x でコンパイルエラーになります。 [ソース] #include <boost/fusion/include/deque.hpp> int main(){ return 0; } エラーは長いので省略。 msvc だと問題なかったです。 もコンパイルエラーになるし、1.50.1 とか来ないかしら。 [参照] http://lists</boost/fusion/include/deque.hpp>…

msvc2010 で boost::for_each を使用するとコンパイルエラーになる

と、いうのを Twitter で見かけたので試してみましたが、コンパイルエラーになりました。 どうやら から #include が削除されているのが原因みたい。 [ソース] #include <boost/range/algorithm/for_each.hpp> #include <iostream> int main(){ int v[] = {1, 2, 3, 4, 5}; boost::for_each(v, [](int n){ s</iostream></boost/range/algorithm/for_each.hpp>…

コンパイラ名を出力する

BOOST_COMPILER で取得できるみたいです。 [ソース] #include <iostream> #include <boost/config.hpp> int main(){ std::cout << BOOST_COMPILER << std::endl; return 0; } [出力] Microsoft Visual C++ version 10.0 [boost] ver 1.50.0 [参照] http://www.boost.org/doc/libs/1_50_0/</boost/config.hpp></iostream>…

Boost 1.50.0 がリリース

Boost 1.50.0 がリリースされました。 Version 1.50.0 Boost 1.50.0 リリースノート(日本語版) [Clang で Boost.Proto を使用した場合の不具合] わたしも先ほど教えて頂いたのですが、clang 3.1(-std=gnu++11) で Boost.Proto を使用するとコンパイルエラー…

TypeErasure で元の型にキャストする

Boost.TypeErasure で処理を呼び出す際に元の型にキャストして渡しています。 template<class C, class T> struct push_back { static void apply(C& cont, const T& arg) { cont.push_back(arg); } }; std::vector<int> vec; any<push_back<_self, int>, _self&> c(vec); int i = 10; call(push_back<_self, int>(), c</_self,></push_back<_self,></int></class>…

引数の組み合わせを Boost.MPL で簡単にする

元ネタ:型に厳格 - きっちん こういう時こそ Boost.MPL の出番ですね。 って事で簡単にやってみました。 [条件] 3つの引数に X が1つでも含まれている関数 plus を定義する [ソース] #include <boost/mpl/count.hpp> #include <boost/mpl/less_equal.hpp> #include <boost/mpl/vector.hpp> #include <boost/utility/enable_if.hpp> struct X{ X(int value) : valu</boost/utility/enable_if.hpp></boost/mpl/vector.hpp></boost/mpl/less_equal.hpp></boost/mpl/count.hpp>…

Boost.TypeErasure でメンバ関数の呼び出しと定義

メンバ関数を呼び出すクラス定義と特殊化を行うことで拡張する事が出来ます。 push_back メンバ関数を呼び出す場合はこんな感じになります。 [ソース] #include <boost/type_erasure/any.hpp> #include <boost/type_erasure/any_cast.hpp> #include <boost/type_erasure/builtin.hpp> #include <iostream> #include <vector> #include <list> template<typename C, typename T> struct push_…</typename></list></vector></iostream></boost/type_erasure/builtin.hpp></boost/type_erasure/any_cast.hpp></boost/type_erasure/any.hpp>

Boost.TypeErasure を使ってみた

と、言うことで以前から気になっていた Boost.TypeErasure をちょっとつついてみました。 [ソース] #include <boost/type_erasure/any.hpp> #include <boost/type_erasure/any_cast.hpp> #include <boost/type_erasure/builtin.hpp> #include <boost/type_erasure/operators.hpp> #include <boost/mpl/vector.hpp> #include <iostream> struct X{ X() : value(0…</iostream></boost/mpl/vector.hpp></boost/type_erasure/operators.hpp></boost/type_erasure/builtin.hpp></boost/type_erasure/any_cast.hpp></boost/type_erasure/any.hpp>

Boost.TypeErasure のコード

Review Request も出ているみたいなので、そろそろつついてみようかなーと思いソースコード探していました。 svn Formal Review Request: TypeErasure ちょっと遊んでみるかなー。

Boost.Fusion の invoke を利用してみる

そういえば、こんな使い方が出来るのよね。 関数テンプレートを直接渡せないのが悲しいけど面白い。 [ソース] #include <sprout/math/sqrt.hpp> template<typename T> constexpr T length(T x, T y, T z){ return sprout::sqrt(x * x + y * y + z * z); } #define BOOST_RESULT_OF_USE_DECLTYPE</typename></sprout/math/sqrt.hpp>…

C++Now! の資料をいくつか読んで

着々と C++Now! の資料が github で公開されているのでチラホラと読んでいます。 まだ全然読めていないんですが、気になったものをいくつか上げてみたいと思います。 基本的にコードしか読んでいないので間違っているかも知れませんがきっと気のせいです。 …

Boost.Xpressive で対応した文字で一括置換

少し前にコメントで教えていただいたので覚書。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> #include <map> int main(){ namespace x = boost::xpressive; using x::_; std::map<std::string, std::string> m = { { "(", "[ " }, { ")", " ]" }, }; x::local<std::string const*> pstr; x::sr…</std::string></std::string,></map></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>

metaparse の meta_hs を使って C++ で Haskell を書く

と、いうことで C++なうで注目を浴び、巷で話題沸騰中の metaparse で Haskell を書いてみました。 まぁ Haskell はあんまり書けないんですけどね! [metaparse] metaparse.pdf - github meta_hs - github [ソース] #define BOOST_MPL_LIMIT_STRING_SIZE 50 …

Boost.Xpressive で HTML タグの中身とタグ名を取得する

こんな感じで簡単に取得出来るみたい。 [ソース] #define _SCL_SECURE_NO_WARNINGS #include <iostream> #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/xpressive_static.hpp> int main(){ namespace x = boost::xpressive; using x::s1; using x::_w; using x::_; // タグで囲まれた文字列を取得 x::mark_tag in_tag(</boost/xpressive/xpressive_static.hpp></boost/xpressive/xpressive.hpp></iostream>…

Boost.Xpressive のセマンティックアクションで整数を受け取る

as を使用します。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> int main(){ namespace x = boost::xpressive; using x::_; int n = 0; x::sregex regex = ("(" >> (x::s1 = -*_) >> ")")[ x::ref(n) = x::as<int>(x::s1) ]; std::string const source = "(1234)"; if( x::rege…</int></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>

Boost.Xpressive でセマンティックアクション

こんなことが出来るみたい。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> #include <string> int main(){ namespace x = boost::xpressive; using x::_; std::string result; x::sregex regex = "(" >> ((x::s1 = -*_)[x::ref(result) = x::s1]) >> ")"; std::string const source</string></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>…

Boost で文字列の置換

boost::algorithm::replace_all_copy あたりを使うのが楽そう。 [ソース] #include <boost/algorithm/string.hpp> #include <iostream> int main(){ std::string source = "homuhomuhomu"; // 結果をコピーして返す auto result1 = boost::algorithm::replace_all_copy(source, "homu", "mado"); st</iostream></boost/algorithm/string.hpp>…

Boost.Filesystem でディレクトリ内の全てのファイルを走査する

Boost.Filesystem の directory_iterator ではディレクトリ直下のファイルしか走査しませんが、recursive_directory_iterator を使用すれば全てのファイルを走査します。 [ソース] #include <iostream> #include <boost/filesystem.hpp> #include <boost/range/algorithm/for_each.hpp> int main(){ namespace f = boost::filesyst</boost/range/algorithm/for_each.hpp></boost/filesystem.hpp></iostream>…

Boost.Xpressive で () の中身を取り出す

mark_tag を使用して、マッチした位置の文字列を取得することが出来ます。 [ソース] #define _SCL_SECURE_NO_WARNINGS #include <iostream> #include <boost/xpressive/xpressive.hpp> int main(){ namespace x = boost::xpressive; x::mark_tag name(1); x::sregex regex = "(" >> (name = -*x::_) >></boost/xpressive/xpressive.hpp></iostream>…

fstream に Boost.Filesystem の path を渡す

Boost.Filesystem に path を受け取る fstream が定義されているらしいです。 [ソース] #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> int main(int argc, char const* argv[]){ namespace fs = boost::filesystem; fs::path exe = argv[0]; fs::ifstream ifs(exe.parent_path()/"mai</boost/filesystem/fstream.hpp></boost/filesystem.hpp>…

Boost.Xpressive で検索位置を走査する

Boost.Spirit.Qi ではなく、Boost.Xpressive で。 sregex_iterator を使用します。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <functional> #include <string> int main(){ namespace x = boost::xpressive; using x::_; std::string source = " (homu) (mado) (mami)"; // () の位置と中身を</string></functional></boost/xpressive/xpressive.hpp>…

Boost.Spirit.Qi のセマンティックアクションで std::string を受け取る

文字列をパースする場合、*qi::char_ のようなパーサを定義すると思いますが、これだと std::vector で受け取る必要があります。 auto parser = '(' >> *(qi::char_ - ')') >> ')'; test_parser("(madohomu)", parser[[](std::vector<char> const& v){ // }]); こ</char>…

Boost.Fusion を使用して構造体から boost::array への変換

Boost.Fusion にアダプトすれば出来るかなーと思って試してみたら問題なく変換されました。 [ソース] #include <boost/array.hpp> #include <boost/fusion/adapted/boost_array.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp> struct vec{ float x; float y; float z; }; BOOST_FUSION_ADAPT_STR…</boost/fusion/include/adapt_struct.hpp></boost/fusion/adapted/struct/adapt_struct.hpp></boost/fusion/adapted/boost_array.hpp></boost/array.hpp>

名前付きタプルが欲しい

メンバ変数だけのクラスとか定義したくないんじゃー。 と、いうことで Boost.Fusion の map と Boost.MPL の string でやってみた。 [ソース] #include <boost/fusion/include/map.hpp> #include <boost/fusion/include/make_map.hpp> #include <boost/fusion/include/at_key.hpp> #include <boost/mpl/string.hpp> #include <boost/typeof/typeof.hpp> #include </boost/typeof/typeof.hpp></boost/mpl/string.hpp></boost/fusion/include/at_key.hpp></boost/fusion/include/make_map.hpp></boost/fusion/include/map.hpp>