Sprout.Weed でコンパイル時に __DATE__ のパース
久々に Sprout.Weed を触りたくなったので。
[ソース]
#include <sprout/weed.hpp> #include <sprout/string.hpp> int main(){ namespace w = sprout::weed; static constexpr auto date = sprout::to_string(__DATE__); static constexpr auto parser = *w::lim<3>(w::char_ - w::space_) >> *w::space_ >> w::int_ >> *w::space_ >> w::int_; static constexpr auto result = w::parse(date.begin(), date.end(), parser); static_assert(result.success(), ""); static_assert(sprout::get<0>(result.attr()) == "Nov", ""); static_assert(sprout::get<1>(result.attr()) == 8, ""); static_assert(sprout::get<2>(result.attr()) == 2012, ""); return 0; }
前に書いてから間があったので、ちょっと手こずるかと思ったんですが、割りとあっさり書けました。
これで2月29日にしかコンパイルできなコードが書けますね!
しかし、やっぱり頭おかしいよな、これ(褒めてる。