2011-07-25から1日間の記事一覧

Boost.Ratio の定義を float っぽく記述する

float というか、実数ですね。 あくまでも、それっぽく記述するだけなので、中身は Boost.Ratio です。 まぁ書きやすくはなるんじゃないでしょうか。 [ソース] #include <boost/mpl/assert.hpp> #include <boost/mpl/equal_to.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> #include <boost/mpl/transform.hpp> #include <boost/ratio/mpl/times.hpp> #include …</boost/ratio/mpl/times.hpp></boost/mpl/transform.hpp></boost/mpl/for_each.hpp></boost/mpl/vector.hpp></boost/mpl/equal_to.hpp></boost/mpl/assert.hpp>

C++ で、Ruby っぽいべき乗計算

C++

Ruby では以下のコードで、べき乗の計算を行うことが出来ます。 puts 2 ** 3 # 8 と、いうことで、C++ でも書いてみました。 [ソース] #include <cmath> #include <iostream> namespace detail{ template<typename T> struct pow_impl{ pow_impl(T const& t) : exponent_(t){} struct expo</typename></iostream></cmath>…