うーん... 正規表現もイテレータも理解していると思っていたのに、C++11 の正規表現の実装には戸惑いました...
理解できない領域の 1 つ: regex token iteratorsについて読んでいると、次のサンプル コードに出くわしました。
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main()
{
std::string text = "Quick brown fox.";
// tokenization (non-matched fragments)
// Note that regex is matched only two times: when the third value is obtained
// the iterator is a suffix iterator.
std::regex ws_re("\\s+"); // whitespace
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
...
}
次の出力の仕方がわかりません。
Quick
brown
fox.
上記の std::copy() 関数によって作成されています。ループが見えないので、反復がどのように行われているかに戸惑います。または別の言い方をすれば、複数行の出力がどのように生成されるのでしょうか?