0

I'm writing a wrapper for std::regex_token_iterator, to split string into vector of strings given a regex seperator. I'm expecting to handle both std::string and std::wstring. But the following code fails to compile.

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;
}

with the error message

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

But I thought std::__cxx11::basic_string<_CharT>::const_iterator is a type. What do I miss here?

kangshiyin
  • 9,681
  • 1
  • 17
  • 29

0 Answers0