C++0x

constexpr な lambda

気がついたら出来ていました。 元々は constexpr 関数内で lambda を使いたかったので、式から型を定義するよな処理を書いていたんですが…。 まだ荒削りですが現状はこんな感じ。 [ソース] #include <cstddef> #include <tuple> #include <utility> namespace half{ template<std::size_t N> struct p</std::size_t></utility></tuple></cstddef>…

constexpr な strtol 関数を書いた

書きました。 constexpr だと代入が出来ないので、第二引数が NULL、もしくは引数が文字列と基数の場合のみ constexpr な値を返します。 [ソース] #include <cstdlib> #include <climits> namespace ce{ // 暫定版 // 英字の連続性は保証されていないので、ぐぬぬ。 template<typename Char> c</typename></climits></cstdlib>…

constexpr を使用したベクトル演算を簡単に書いてみた

ベクトル型同士の演算しか出来ませんが、簡単に書いてみました。 [ソース] #include <iostream> template<typename T> struct vec3{ typedef T value_type; static int const dimension = 3; union{ struct{ value_type x, y, z; }; value_type array[dimension]; }; }; template<typename T> c</typename></typename></iostream>…

Template Aliases でハマった

Template Aliases でハマったので覚え書き。 まーしょっぱいエラーですね。 次のコードはエラーになります。 [ソース] #include <boost/mpl/has_xxx.hpp> #include <boost/mpl/identity.hpp> #include <boost/mpl/if.hpp> namespace mpl = boost::mpl; BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type); template<typename T> using T_value_type =</typename></boost/mpl/if.hpp></boost/mpl/identity.hpp></boost/mpl/has_xxx.hpp>…

C++0x で関数ポインタ型を定義

alias declaration(Template Aliases) が実装されていれば using を使用して、わかりやすく関数ポインタ型を定義できるので試してみたました。 [ソース] #include <boost/mpl/assert.hpp> #include <boost/type_traits/is_same.hpp> #include <iostream> using func_type = int(*)(int, int); // typedef int(*func_type)(int</iostream></boost/type_traits/is_same.hpp></boost/mpl/assert.hpp>…

C++ and C++'0x Support in Clang

が更新されたらしいので、『template aliases』と『In-declaration member initialization』を試してみました。 C++ and C++'0x Support in Clang 他にも更新されたのがあるかも。 [ソース] #include <iostream> #include <boost/array.hpp> template<typename T, typename U> struct is_same{ static bool const</typename></boost/array.hpp></iostream>…

C++0x の右辺値参照がこんなに難しいわけがない。

C++0xのアレです。 これに関してはさんざん解説がされているとは思いますが、自分がイマイチ理解していなかったのでまとめてみました。 概念や細かい仕様なんかは書いてないのでありからず…。 あとテスト用のコンパイラは、gcc-4.5.0 です。 ☆参照渡し C++ …

ラムダは便利だな

今までスコープの外の変数を使う場合は、BOOST_FOREACH を使っていたんですが、 int sum = 0; BOOST_FOREACH(int n, boost::counting_range(0, 10)){ sum += n; } [&]にすればスコープの外をキャプチャ出来るんですね。 int sum = 0; boost::for_each(boost:…