0
の控除前:使用::花:: eval_if_tコードスニペットは、段落のカップルよりも多くを語る自動
#include <boost/hana/fwd/eval_if.hpp>
#include <boost/hana/core/is_a.hpp>
#include <iostream>
#include <functional>
using namespace boost::hana;
template<class arg_t>
decltype(auto) f2(arg_t const& a)
{
constexpr bool b = is_a<std::reference_wrapper<std::string>,
arg_t>;
auto wrapper_case = [&a](auto _) -> std::string&
{ return _(a).get(); };
auto default_case = [&a]() -> arg_t const&
{ return a; };
return eval_if(b, wrapper_case, default_case);
}
int main()
{
int a = 3;
std::string str = "hi!";
auto str_ref = std::ref(str);
std::cout << f2(a) << ", " << f2(str) << ", " << f2(str_ref)
<< std::endl;
}
コンパイルエラーがある:
$> g++ -std=c++14 main.cpp
main.cpp: In instantiation of ‘decltype(auto) f2(const arg_t&) [with arg_t = int]’:
main.cpp:42:22: required from here
main.cpp:31:19: error: use of ‘constexpr decltype(auto) boost::hana::eval_if_t::operator()(Cond&&, Then&&, Else&&) const [with Cond = const bool&; Then = f2(const arg_t&) [with arg_t = int]::<lambda(auto:1)>&; Else = f2(const arg_t&) [with arg_t = int]::<lambda(auto:2)>&]’ before deduction of ‘auto’
return eval_if(b, wrapper_case, default_case);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
何の再帰はありません、私はおそらくdecltype(auto)
についてのいくつかのバグを解決し、完全に動作するC++ 14の実装を持っており、boost::hana
の要件に適合するgcc-6.0.2を使用するので、私の実装には私のエラーがなければなりません。約エラー。
:clang ++ 3.8.0は、同様のコンパイラエラーをスローします。
何らかの理由で、一部のテンプレートがfwdファイルに完全に実装されていましたが、私はちょうど 'hana'ドキュメントにあるヘッダを取りました。 'b'の問題は完全に理解していません。 'b'それはコンパイル時に知られている一定値なので、' eval_if'は期待通りに動作するはずです。 –
@ Peregring-lk値の定数は、関数の引数として渡されると失われます。それが動作するためには型に埋め込まなければなりません。 –
>私はちょうど花のドキュメントにあるヘッダーを取ってきました。 @ Peregring-lkドキュメンテーションでその例をどこから入手したか教えてください。 'boost/hana/eval_if.hpp'が含まれていなければならないことを明確にしなければ、修正したいと思います。 –