/// function template match<> to match a string
/// with a parameterized regex.
#include <regex>
#include <iostream>
usingnamespace std;
vector<string> lines {"TX77845", "TX 77504", "Hello"};
/// US ZIP code pattern: XXddddd-dddd and variants
regex USZipCode {R"(\w{2}\s*\d{5}(-\d{4})?)"};
template<typename R>
void rmatch(string s)
{
/// matched strings go here
smatch matches;
if (regex_match(s, matches, R)) /// line 27: 1st error here
cout << "match : " << matches[0] << '\n';
else
cout << "no match\n";
cout << endl;
}
int main()
{
for (auto l : lines)
{
/// matched strings go here
smatch matches;
rmatch<USZipCode>(l); /// line 43: 2nd error here
}
}
In function 'void rmatch(std::string)':
27:34: error: expected primary-expression before ')' token
In function 'int main()':
43:28: error: no matching function for call to 'rmatch(std::basic_string<char>&)'
43:28: note: candidate is:
22:6: note: template<class R> void rmatch(std::string)
22:6: note: template argument deduction/substitution failed:
I'm unable to figure out the reason for these errors. Why is this happening?