std::match_results with std::basic_string (regex)

I am trying to construct a regex matcher for a basic string so that I have a generalized regex matching function for any string type. I am getting a syntax error I can't figure out. I have included the compile log and source below.

The specific line giving me grief is line 19 below. I repeat it here:
std::match_results<std::basic_string<CharType>::const_iterator> Pieces;

Any insight would be most appreciated.

Regards,

David

Here is the compile log:
08:37:59 **** Incremental Build of configuration Debug for project Test ****
make all
Building file: ../src/Test.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Test.d" -MT"src/Test.d" -o "src/Test.o" "../src/Test.cpp"
../src/Test.cpp: In function ‘std::vector<std::basic_string<_CharT> >& RegEx(std::vector<std::basic_string<_CharT> >&, const std::basic_string<_CharT>&)’:
../src/Test.cpp:19:65: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Bi_iter, class _Allocator> class std::match_results’
std::match_results<std::basic_string<CharType>::const_iterator> Pieces;
^
../src/Test.cpp:19:65: error: expected a type, got ‘std::basic_string<_CharT>::const_iterator’
../src/Test.cpp:19:65: error: template argument 2 is invalid
../src/Test.cpp:19:73: error: invalid type in declaration before ‘;’ token
std::match_results<std::basic_string<CharType>::const_iterator> Pieces;
^
make: *** [src/Test.o] Error 1

08:38:00 Build Finished (took 712ms)


Here is the source:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <vector>
#include <regex>

template <typename CharType>
std::vector<std::basic_string<CharType> > &RegEx(std::vector<std::basic_string<CharType> > &Matches,
    const std::basic_string<CharType> &MatchString);

int main(int argc, char *argv[])
{
	return 0;
}

template <typename CharType>
std::vector<std::basic_string<CharType> > &RegEx(std::vector<std::basic_string<CharType> > &Matches,
    const std::basic_string<CharType> &MatchString)
{
  std::basic_regex<CharType> PatternRegEx(MatchString);
  std::match_results<std::basic_string<CharType>::const_iterator> Pieces;
//  std::match_results<std::string::const_iterator> Pieces;
//  Matches.clear();
//  if (std::regex_match(MatchString, Pieces, PatternRegEx))
//  {
//    Matches.resize(Pieces.size());
//    for (size_t i = size_t(0); i < Pieces.size(); ++i)
//    {
//      Matches[i] = Pieces[i].str();
//    }
//  }

  return Matches;
}


Line 19: the dependant type name needs to be disambigated.

1
2
// std::match_results<std::basic_string<CharType>::const_iterator> Pieces;
std::match_results< typename std::basic_string<CharType>::const_iterator > Pieces;


Note: With the GNU toolchain, GCC 4.9 (released a few days back) is required for std::regex

Perfect! Thanks for the quick reply and the extra note.
Topic archived. No new replies allowed.