std :: regex_token_iterator的模板参数

时间:2017-05-19 04:04:00

标签: c++ regex c++11 stl

我正在编写std::regex_token_iterator的包装器,在给定正则表达式分隔符的情况下将字符串拆分为字符串向量。我期待同时处理std::stringstd::wstring。但是以下代码无法编译。

template<typename CharT>
bool SplitString(const std::basic_string<CharT>& str,
                 const std::basic_regex<CharT>& regex_seperator,
                 std::vector<std::basic_string<CharT>>* str_vec) {

  std::regex_token_iterator<std::basic_string<CharT>::const_iterator> first {
      str.begin(), str.end(), regex_seperator, -1 }, last;
  *str_vec = {first, last};
  return true;
}

带有错误消息

src/utils/common.h: In function ‘bool SplitString(const std::__cxx11::basic_string<_CharT>&, const std::__cxx11::basic_regex<CharT>&, std::vector<std::__cxx11::basic_string<_CharT> >*)’:
src/utils/common.h:92:69: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Bi_iter, class _Ch_type, class _Rx_traits> class std::__cxx11::regex_token_iterator’
   std::regex_token_iterator<std::basic_string<CharT>::const_iterator> first {
                                                                     ^
src/utils/common.h:92:69: note:   expected a type, got ‘std::__cxx11::basic_string<_CharT>::const_iterator’
src/utils/common.h:92:69: error: template argument 2 is invalid
src/utils/common.h:92:69: error: template argument 3 is invalid

但我认为std::__cxx11::basic_string<_CharT>::const_iterator是一种类型。我在这里想念什么?

0 个答案:

没有答案