diff --git a/libs/weed/example/__TIME__.cpp b/libs/weed/example/__TIME__.cpp new file mode 100644 index 00000000..e6283cb8 --- /dev/null +++ b/libs/weed/example/__TIME__.cpp @@ -0,0 +1,68 @@ +// +// Sprout C++ Library +// +// Copyright (c) 2012 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/osyo-manga/cpp-half/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include +#include +#include +#include + +// +// __TIME__ Parser +// +int +main(){ + namespace w = sprout::weed; + + // + // __TIME__ to Sprout.String + // + static constexpr auto time = sprout::to_string(__TIME__); +// static constexpr auto time = sprout::to_string("23:22:45"); + + + // + // parse __TIME__ + // + constexpr auto parser = w::int_ >> ':' >> w::int_ >> ':' >> w::int_; + static constexpr auto result = w::parse(time.begin(), time.end(), parser); + static_assert(result.success(), "failed parse"); + + + // + // get result + // + static constexpr sprout::array result_attr = result.attr(); + static constexpr auto hour = result_attr[0]; + static constexpr auto minute = result_attr[1]; + static constexpr auto second = result_attr[2]; + +// static_assert(hour == 23, ""); +// static_assert(minute == 22, ""); +// static_assert(second == 45, ""); + + std::cout << hour << std::endl; + std::cout << minute << std::endl; + std::cout << second << std::endl; + + + // + // compile time output + // + namespace m = boost::mpl; + typedef m::print>::type hour_; + typedef m::print>::type minute_; + typedef m::print>::type second_; + + return 0; +}