0

セミコロンで区切られた数字で c-string をトークン化し、それらをベクトルに格納しようとしています。これは私の単純化されたアプローチです

auto string = "1;2;3;4";
const std::regex separator {";"};
std::cregex_token_iterator t_begin{string, string + strlen(string), separator, -1};
std::cregex_token_iterator t_end{};
auto begin = boost::make_transform_iterator(t_begin, atoi);
auto end = boost::make_transform_iterator(t_end, atoi);
std::vector<int> result{begin, end};

エラーメッセージが表示されます:

error: no type named 'type' in 'boost::mpl::eval_if<boost::is_same<boost::iterators::use_default, boost::iterators::use_default>, boost::result_of<const int(std::sub_match<const char*>&)>, boost::mpl::identity<boost::iterator::use_default> >::f_{aka struct boost::result_of<const int(const std::sub_match<const char*>&)>}'
typedef typename f_::type type;

わかりません。

4

1 に答える 1

1

std::cregex_token_iteratorstd::sub_matchを逆参照すると、対応する型の が返されます。この場合、それはconst char*ポインターのペアであるため、考えられる解決策は次のとおりです。

auto f = [] (std::csub_match m) { return std::atoi(m.first); };

auto begin = boost::make_transform_iterator(t_begin, f);     
auto end = boost::make_transform_iterator(t_end, f);

デモ

于 2016-06-01T11:02:24.407 に答える