2017-01-10 6 views
1

私はhana::tuple_t<int, char, double, float>を持っています。これを使ってhana::tuple<int, char, double, float>を作成します。hana :: tuple_tからhana :: tupleに行く

私はhana::to<hana::tuple_tag>を使用するとhana::tuple_t<int, char, double, float>hana::tuple<int, char, double, float>に変換すると考えました。次は必ず失敗するので、それはそうではありません。

auto oType = hana::tuple_t<int, char, double, float>; 

BOOST_HANA_CONSTANT_ASSERT(
    hana::to<hana::tuple_tag>(oType) 
    == 
    hana::make_tuple(1, 'C', 1.0, 1.0f) 
); 

私もhana::transformを使用してみましたが、運(私は私が間違ってそれをやっている疑いがある)としました:

auto vecs = hana::transform(typeList, [](auto t) { 
    return typename decltype(t)::type{}; 
}); 

だから、どうすればhana :: tuple_tをhana :: tupleに変えることができますか?

+1

デフォルトの初期化では、「1」(または「1.0」または「C」)ではなく「0」の値が生成されます。これをタプル 'hana :: make_tuple(0、 '\ 0'、0.0、0.0f)'と比較しようとしましたか? – Cornstalks

+0

ええ、私はそれを試みました。重大度\t \t static_assertが失敗しました "hana :: to (oType)== hana :: make_tuple(0、0.0、0.0f)" – Acorn

答えて

2

私はhana::template_hana::metafunctionなどの

#include <boost/hana.hpp> 
namespace hana = boost::hana; 

constexpr auto types = hana::tuple_t<int, char, double, float>; 
using Tuple = decltype(hana::unpack(types, hana::template_<hana::tuple>))::type; 
// Tuple is hana::tuple<int, char, double, float> 
// Now you can create such a tuple as you wish: 
Tuple ts{1, 'x', 2.2, 3.4f}; 

ものはタイプで、この相互運用を行うために、正確に建設されたように、あなたが本当にここにしたいことは何かであると考えています簡単です。

3

hana::tuple_tはそれ自体が既にhana::tupleのテンプレート変数であるため、hana::tupleに変換すると何も変わりません。あなたは整数型の値のような0を期待するよう

コメントで述べたように
template <typename ...T> 
constexpr hana::tuple<hana::type<T>...> tuple_t{}; 

は、hana::transformデフォルトへのお電話は、各メンバーを初期化します。

また、コンパイル時の値のみをチェックするBOOST_HANA_CONSTANT_ASSERTを使用しています。生のint,char,doubleおよびの値はconstexprではありません。実行時の値の

BOOST_HANA_RUNTIME_ASSERT作品:

#include <boost/hana.hpp> 

namespace hana = boost::hana; 

constexpr auto types = hana::tuple_t<int, char, double, float>; 

struct init_from_type_fn 
{ 
    template <typename Type> 
    constexpr auto operator()(Type) const 
    { 
    return typename Type::type{}; 
    } 
}; 

constexpr init_from_type_fn init_from_type{}; 

int main() 
{ 
    BOOST_HANA_RUNTIME_ASSERT(
    hana::equal(
     hana::transform(types, init_from_type), 
     hana::make_tuple(0, '\0', 0.0, 0.0f) 
    ) 
); 
} 
+0

MSVC w/Clangのように見えます。それはちょうどこのコードが好きではありませんが、Clangを使って私のVM上で正常に動作します。 – Acorn

+0

エラーは何ですか?たぶんそれは 'C++ 14'を特定していないでしょうか?私はMSVCを使用していませんが、私はHanaを使っている人について聞いたことがあります。 –

+0

これは 'シグナルの使用により失敗したclang frontendコマンド 'です。私が集めたことから、コンパイラはすべてをまとめようとすると混乱しています。 '-v' afaikを投げる方法はないので、私はそれをレンガの壁と考えました。 – Acorn

関連する問題