2013-07-01から1ヶ月間の記事一覧

Cプリプロセッサの挙動の違い

Cプリプロセッサというのはgcc, clang, MSVCなどの処理系ごとに微妙に異なります。 #pragmaディレクティブなどは、各コンパイラ等の独自拡張機能をサポートする為などに使われていますが、Cプリプロセッサの差というのはサポートする機能の有無やキーワード…

boost mpl から fusion へ変換する

mpl::vector< T... > に列挙された型を要素とするfusion::vector< T... >を作る方法が思いつかなくて頭を抱えている— Fadis (@fadis_) July 29, 2013 こんな感じですかね。 #include <type_traits> #include <boost/fusion/container/vector.hpp> #include <boost/mpl/list.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/deque.hpp> #include </boost/mpl/deque.hpp></boost/mpl/vector.hpp></boost/mpl/list.hpp></boost/fusion/container/vector.hpp></type_traits>

ユーザ定義リテラルからpairを作る

ユーザ定義リテラルはその制約のキツさから全然融通が効かないので、あんまり遊べる要素とか面白い利用法とかが見つからないのですが、少し変わった利用が出来ないか考えてみました。 #include <type_traits> namespace ct { static constexpr std::size_t period = stati</type_traits>…

文字列リテラルから型文字列を作る1

これまで数多くの人が型文字列の生成において<'h','e','l','l','o'>などの入力で深い悲しみを感じて来ました。 C++11で生まれたユーザ定義リテラルは、数値からであれば型文字列を生成出来ますが文字列リテラルには適用できません。 以前プリプロセッサで実…

条件演算子の戻り値にはthrow-expressionを書くことが出来る

5.16 Conditional operator If either the second or the third operand has type void, then the lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed on the second and third operands, …

Template Meta Programming 1

標準ライブラリのtype_traitsにあるis_sameを自分で実装してみましょう。 恐らく最も簡単なメタ関数の1つです。 integral_constant、true_type、false_typeも標準ライブラリ通りに準備します。 is_sameでは与えられた2つの型が同じであった場合の特殊化を行…

index_tuple idiom

勉強会のスライドなんかでこの名前で見かけます。 非常によく知られたidiomですが、メモ程度に簡単にまとめ直します。 index_tuple idiomはindex_tuple<0,1,2,3,4>のように連番の整数値を型リストとして持つオブジェクト(index_tuple)を生成する為のidiomで…