Code:
template <typename T>
auto RegexSearch(T const* str,
T const* regex)
{
using iter = T const*;
std::basic_regex<T> re(regex);
std::match_results<iter> m;
std::regex_search(str, m, re);
return m;
}
auto matches = RegexSearch(L"10,20", LR"((\d+))");
// ------------------------------------------------------------- //
template <typename T>
auto RegexSearch(const std::basic_string<T>& str,
const std::basic_string<T>& regex)
{
using iter = typename std::basic_string<T>::const_iterator;
std::basic_regex<T> re(regex);
std::match_results<iter> m;
std::regex_search(str, m, re);
return m;
}
auto matches = RegexSearch(L"10,20"s, LR"((\d+))"s);
what's the difference between passing parameters to the template as
T const * str <--- this 'method', m return correct values
and
const std::basic_string<T>& str <--- this, m return garbage (because the string lives only inside of the template scope(??))
some questions i got:
1. there are any 'cons' in passing parameters to templates as i did in the first template?
2. is the basic_string method 'faster'? why? or theres no difference between these two methods?
i'm a beginner in c++