0

gsl::span混合バイナリ/ASCIIデータのパックされた構造(したがって novectorまたはstring)から正規表現で操作したい関数にデータを渡すために使用しようとしていますが、次のエラーが発生します:

エラー C2784: 'bool std::regex_match(_BidIt,_BidIt,std::match_results<_BidIt,_Alloc> &,const std::basic_regex<_Elem,_RxTraits> &,std::regex_constants::match_flag_type)': 推定できませんでした'std::cmatch' からの 'std::match_results>,_Alloc> &' のテンプレート引数

「std::regex_match」の宣言を参照してください

これが私がやろうとしていることです:

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

using namespace std;
using namespace gsl;

int main(int argc, const char **argv) 
{
    char lat[8] = { '0', '1', '9', '0', '0', '0', '0', 'E' };
    span<char> s = lat;

    // in a complex implementation this would be in a function,
    // hence the desire for span<>
    std::cmatch match;
    std::regex_match(s.begin(), s.end(), match, std::regex("[0-9]+"));
}
4

1 に答える 1

2

問題は、イテレータ型がa をイテレータ型として使用するためstd::regex_match、関数のオーバーロードを解決できないことです。この場合はどちらも適切ではありません。独自の型が必要です。方法は次のとおりです。gsl::continuous_span_iteratorstd::cmatchconst char*std::smatchstd::cmatchstd::match_results

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

using namespace std;
using namespace gsl;

int main(int argc, const char **argv) 
{
    char lat[8] = { '0', '1', '9', '0', '0', '0', '0', 'E' };
    span<char> s = lat;
    std::match_results<decltype(s)::iterator> match;
    std::regex_match(s.begin(), s.end(), match, std::regex(".*"));
}

とはいえ、この記事の執筆時点では、修正されたイテレータ アプローチは問題 #271のためにまだコンパイルされません。

それが修正されるまで、別の回避策は次のとおりです。

int main(int argc, const char **argv) 
{
    char lat[8] = { '0', '1', '9', '0', '0', '0', '0', 'E' };
    span<char> s = lat;
    std::cmatch match;
    std::regex_match(&s[0], &s[s.length_bytes()], match, std::regex(".*"));
}

回避策のアプローチは、同じまたは異なるエクステントのスパンが関数に渡されるケースをカバーします。

于 2016-02-24T23:08:50.753 に答える