2014-03-01から1ヶ月間の記事一覧

関数テンプレートを使ってメタ関数の実装を書く

特にメリットとか無いのですが、こういう風にも書けるわなと思ったので書いてみました。 #include <type_traits> template<std::size_t... Indices> struct index_tuple {}; template<std::size_t M, std::size_t N> struct index_range { private: template<std::size_t STEP, std::size_t LAST, std::size_t... Indices> static auto impl(typename std::enable_if<…</std::size_t></std::size_t></std::size_t...></type_traits>

templateキーワードを複数行書くケース

sprout::tupleの実装などに見られる。ネストされたtemplate関数の実装を書く場合等に使う。あまり見かけないからか、解説されてない気がしたのでメモ程度に残しておきます。複数書く場合は、外側のテンプレートに対応するものから順番に書きます。 template <typename T1, typename T2></typename>…

tupleからvariantのarrayに変換する

タイトル通りです。もしかしたら便利な事があるかもしれません。 #include <sprout/tuple.hpp> #include <sprout/array.hpp> #include <sprout/variant.hpp> #include <sprout/index_tuple.hpp> template <typename... Types, sprout::index_t... Indices> constexpr auto tuple_to_varray_impl(const sprout::tuple<Types...>& t, const sprout::index_tu…</types...></typename...></sprout/index_tuple.hpp></sprout/variant.hpp></sprout/array.hpp></sprout/tuple.hpp>

apply

関数オブジェクトとtupleを渡すとtupleの各要素を引数として関数を呼び出すいわゆるapplyの動作をする関数を実装してみました。sproutには既にmake_fusedという非常に便利な関数があるのでこれを適用した後に関数を呼び出す処理までをラップすれば同じ効果が…