続・C++でStringTokenizerっぽいことをやってみる

| | TrackBacks (0)

 前回の記事haveの指摘に従い、参照渡しをやめてヴェクタを返す関数にしてみた。

std::vector<string> 
slice(const std::string source, const std::string dem)
{
  std::string::size_type i1 = 0;
  std::string::size_type i2 = source.find(dem);
  std::vector<string> retval;

  if(std::string::npos == i2)
    return retval;

  std::string s = source + dem;

  do{
    retval.push_back(s.substr(i1, i2-i1));
    i1 = i2+1;
  }while(std::string::npos != (i2 = s.find(dem, i1)));

  return retval;
}

 ちょっと効率は落ちたが、Atomicになったので前回のコードにくらべ、マルチスレッドプログラミングで安全に使えるようになった。

Thanks! nice comment > Have

Categories

0 TrackBacks

Listed below are links to blogs that reference this entry: 続・C++でStringTokenizerっぽいことをやってみる.

TrackBack URL for this entry: http://www.argv.org/~chome/blog/mt-tb.cgi/77

About Me

中尾 圭佐(chomy)
千葉県船橋市在住のモノクロ写真に目覚めた研究者。
Twitter ID: jm6xxu
Skype: chomy

My Tweets

jm6xxu: 今日は朝7:30から仕事を始め、午後から夜まで都内で会議。その後途中で呑んで、現在帰宅中。抽選から漏れた本を、当選者の方に譲っていただける事になったし、自分の仕事は一切できなかったが、良い一日だった。

jm6xxu: @atelieraterui @jm6xxu 最近は忙しくてなかなか出れませんが、ときどき移動で7,21,50,144,430MHzに出ています。聞こえていたらよろしくお願いします。

jm6xxu: @atelieraterui 本当ですか!ありがとうございます。のちほど送付先を連絡させていただきます。

jm6xxu: @mehori 了解しました。当選した場合、一括してお引き受けいたします。Google Docで論文まで書かれるということで、そこまで使えるようになりましたか。私もそろそろAnnual Reportを書かなければならないので、試してみることにします。

jm6xxu: @mehori Making TeX Work ください。TeXを廃止されて次は何を使われるのですか?

About this Entry

This page contains a single entry by chomy published on June 14, 2009 3:16 AM.

C++でStringTokenizerっぽいことをやってみる was the previous entry in this blog.

MacBookPro 購入 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.261