我只找到的regex_iterators
例子被intialised作爲regex_iterators可以用於自定義字符串類型嗎?
regex_iterator::<string::iterator>
如果我有一個包含字符序列的一類,例如:
class fooString {
private:
deque<bar> data;
// ... other functionality ...
}
凡bar
是一個類或結構是兼容std::to_string
如何使fooString
和bar
與正則表達式兼容,以便我可以撥打
fooString myFoo = ...
regex e(/* some regex notation */);
regex_iterator::<fooString::iterator> regIt(myFoo.begin(), myFoo.end(), e);
......並且能夠像對字符串一樣遍歷它嗎?
我嘗試了以下實驗性功能:
std::deque<int> testDeque { 4, 5, 5, 5, 6, 7 };
std::regex e("5{1,3}");
std::regex_iterator<std::deque<int>::iterator>
regIt(testDeque.begin(), testDeque.end(), e);
並得到編譯錯誤
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\regex(2271): error C2027: use of undefined type 'std::regex_traits<_Elem>'
with
[
_Elem=int
]
所以我不認爲雙向迭代器就足夠了,因爲雙端隊列與遵守,我認爲'酒吧'對象需要兼容。但我真的不確定。
根據[此std :: regex_iterator參考](http://en.cppreference.com/w/cpp/regex/regex_iterator),迭代器需要是[雙向迭代器](http:// en.cppreference.com/w/cpp/concept/BidirectionalIterator)。所以如果你的迭代器滿足雙向迭代器的要求,那麼你很好。 –
@Someprogrammerdude我認爲數據類型Bar也需要滿足一些特定的屬性,但我不知道它是什麼。 – Ian