2007年5月8日
一般來說vector不適合做經(jīng)常刪除的容器,但是在某些情況下,我們確實(shí)需要?jiǎng)h除vector的部分元素,一般的方式類為v.erase(remove_if(v.begin(), v.end(), func)).但是本人懶的把操做寫到另一個(gè)函數(shù)中,下面是一個(gè)更好的辦法
vector<int>::reverse_iterator rit = v.rbegin();
while (rit != v.rbegin())
{
if (func(*rit)) //檢查是否需要?jiǎng)h除
v.erase((++rit).base());
else
++rit;
}
其中reverse_iterator和iterator的關(guān)系與轉(zhuǎn)換是關(guān)鍵,STL真是設(shè)計(jì)的強(qiáng)大.
2007年3月31日
使用VIM編寫程序,發(fā)現(xiàn)切換頭文件和代碼文件很麻煩,發(fā)現(xiàn)一個(gè)好東西A.vim,具體使用參數(shù)如下:
A switches to the header file corresponding to the current file being edited (or vise versa)
:AS splits and switches
:AV vertical splits and switches
:AT new tab and switches
:AN cycles through matches
:IH switches to file under cursor
:IHS splits and switches
:IHV vertical splits and switches
:IHT new tab and switches
:IHN cycles through matches
<Leader>ih switches to file under cursor
<Leader>is switches to the alternate file of file under cursor (e.g. on??<foo.h> switches to foo.cpp)
<Leader>ihn cycles through matches
下載地址如下:http://www.vim.org/scripts/script.php?script_id=31
下載后放到/usr/share/vim/vim61/plugin/就可以了,如果啟動(dòng)時(shí)候有錯(cuò)誤,就下載一個(gè)老一點(diǎn)的版本.
indent是一個(gè)常用的Linux的C代碼格式化工具,但是參數(shù)太多,很難記憶,目前發(fā)現(xiàn)一組參數(shù),可以格式化為我常用的代碼格式.
-bad?-bap?-bbb?-bbo?-nbc?-bl?-bli0?-bls?-c33?-cd33?-ncdb?-ncdw?-nce?-cli0?-cp33?-cs?-d0?-nbfda??-nfc1?-nfca?-hnl?-ip5?-l75?-l
p?-pcs?-nprs?-saf?-sai?-saw?-nsc?-nsob?-nss?-i4?-ts4?-ut
保存在~/.indent.pro,就是默認(rèn)的indent參數(shù)了.
2007年3月12日
從Google上發(fā)現(xiàn)了這個(gè)C++專門的Blog,發(fā)現(xiàn)很不錯(cuò),有自己寫的欲望了,申請(qǐng)了一下,今天開張,希望能記錄一些經(jīng)驗(yàn),保存一些自己看到的比較好的文章.