[boost]Boost C++ Libraryのお勉強その9

boost::hash

hash関数。興味ないので飛ばす。

boost::fusion

tupleは各要素の型が違うのでSTLアルゴリズムが使えないので、その辺に対応したもの。

#include <iostream>
#include <string>

#include <boost/fusion/tuple.hpp>
#include <boost/fusion/algorithm.hpp>

struct Print
{
    template < typename T > void operator () (T & x) const
    {
        std::cout << x << std::endl;
    }
};

int main(void)
{
    boost::fusion::tuple < int, std::string > t(1, "alfa");
    boost::fusion::for_each(t, Print());

    return 0;
}
1
alfa

discards qualifiersとかいうコンパイルエラーが、関数をconstにしてないという意味なのに気がつかず、かなり時間を消費してしまった。

boost::gil

Generic Image Libraryの略。ドキュメントが凄くて、音声付き(英語だけど)のスライドでGILを紹介する動画がある。ゆっくりはっきり喋ってるので聞き取りやすい。
それはそれとして、GILってadobeの人が作ってるらしくadobeがスポンサみたい。ドキュメントのトップにロゴがでてるけど、boostってそういうのもありなのか?

なんか面倒そうなのでコードはパス。

はてなダイアリーのバージョンが変わってバグった?

昔書いたコードが表示されていない。
http://d.hatena.ne.jp/vtwinautomaton/20081124/1227529806

googleのキャッシュを見るとコードが表示されてる。
http://72.14.235.132/search?q=cache:7i_uc3w6w14J:d.hatena.ne.jp/vtwinautomaton/20081124/1227529806+Boost+C%2B%2B+Library%E3%81%AE%E3%81%8A%E5%8B%89%E5%BC%B7%E3%81%9D%E3%81%AE2&hl=ja&ct=clnk&cd=1&gl=jp&client=firefox-a

htmlのソースを見てもincludeしか出力されてない。

はてなダイアリーのバージョンが変わってバッグったのかな?

Boost C++ Libraryのお勉強その8

functionとかfunctionalとか紛らわしいんですが…。

Boost.Function

関数っぽいものを保持できるクラス。structの定義をmain()内に書いたらコンパイルできないのにちょっとハマった。

#include <iostream>
#include <boost/function.hpp>

struct pow4
{
    int operator() (int x) const { return x * x * x * x; };
};

int main(void)
{
    boost::function<int (int x) > fun;
    fun = pow4();
    std::cout << fun(4) << std::endl;
    return 0;
}
256

Boost.Function_Types

関数の型チェックとか色々。

#include <iostream>
#include <boost/function_types/is_function_pointer.hpp>

int main(void)
{
    std::cout << boost::function_types::is_function_pointer < int (*) (void) >::value << std::endl;
    return 0;
}
1

Boost.Functional

STLのやつを拡張したもの。

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <boost/functional.hpp>

int main(void)
{
    std::string s = "abcdef@";
    std::cout << *std::find_if(s.begin(), s.end(), boost::not1(isalpha)) << std::endl;
    return 0;
}
@