本当は怖い○○童話、にかけようと思ったんですが、
boost がキモいのは既に周知の事実ですのでこのタイトルになりました。
さて、boost の中でキモいものと言えば、spirit, mpl, fusion などいろいろありますが、
今回はこの中でも boost::mpl を取り上げてみましょう。
例えばこんな構造体を考えてみます。
struct expr { template <typename T> struct apply { typedef boost::shared_ptr<T> type; }; };
これを使うと、
expr::apply<int>::type => boost::shared_ptr<int> expr::apply<char>::type => boost::shared_ptr<char>
というように、型(int, char)を引数に、型(shared_ptr
すなわち、これは「関数である」と言えますね!
よって、これを mpl::transform の述語関数として使用します。
typedef boost::fusion::vector3<int, char, long> vector_type; typedef typename boost::mpl::transform<vector_type, expr>::type ptr_vector_type;
これで、ptr_vector_type は、
boost::fusion::vector3< boost::shared_ptr<int>, boost::shared_ptr<char>, boost::shared_ptr<long> >
型になります。