mercredi 24 février 2016

gsl::span fails to compile with std::regex

I'm trying to use gsl::span to pass some data from a packed structure of mixed binary/ascii data (hence no vector or string) to a function, where I want to operate on it with a regex, but I get the following errors:

error C2784: 'bool std::regex_match(_BidIt,_BidIt,std::match_results<_BidIt,_Alloc> &,const std::basic_regex<_Elem,_RxTraits> &,std::regex_constants::match_flag_type)' : could not deduce template argument for 'std::match_results>,_Alloc> &' from 'std::cmatch'

see declaration of 'std::regex_match'

Here's what I'm trying to do:

#include <regex>
#include <gsl.h>

std::string matchSomething(gsl::span<char> value)
{
    std::cmatch matches;
    std::regex_match(value.begin(), value.end(), matches, std::regex("(.*)"));
    return matches[0];
}

int main(int argc, const char **argv) 
{
    char str[10] = "123456789";  // packed struct simulator
    matchSomething(gsl::as_span(str));
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire