顯示具有 Computer 標籤的文章。 顯示所有文章
顯示具有 Computer 標籤的文章。 顯示所有文章

BOOST 1.35.0 is out!

boost 更新了!增加了十一個新的 library。

New Libraries
* Asio:
Portable networking, including sockets, timers, hostname resolution and socket iostreams, from Chris Kohlhoff.

* Bimap:
Boost.Bimap is a bidirectional maps library for C++. With Boost.Bimap you can create associative containers in which both types can be used as key, from Matias Capeletto.

* Circular Buffer:
STL compliant container also known as ring or cyclic buffer, from Jan Gaspar.

* Function Types:
Boost.FunctionTypes provides functionality to classify, decompose and synthesize function, function pointer, function reference and pointer to member types. From Tobias Schwinger.

* Fusion:
Library for working with tuples, including various containers, algorithms, etc. From Joel de Guzman, Dan Marsden and Tobias Schwinger.

* GIL:
Generic Image Library, from Lubomir Bourdev and Hailin Jin.

* Interprocess:
Shared memory, memory mapped files, process-shared mutexes, condition variables, containers and allocators, from Ion Gaztañaga.

* Intrusive:
Intrusive containers and algorithms, from Ion Gaztañaga.

* Math/Special Functions:
A wide selection of mathematical special functions from John Maddock, Paul Bristow, Hubert Holin and Xiaogang Zhang.

* Math/Statistical Distributions:
A wide selection of univariate statistical distributions and functions that operate on them from John Maddock and Paul Bristow

* MPI:
Message Passing Interface library, for use in distributed-memory parallel application programming, from Douglas Gregor and Matthias Troyer.

* System:
Operating system support, including the diagnostics support that will be part of the C++0x standard library, from Beman Dawes.

加了不少實用的東西,看來至少可以先玩玩 ASIO 還有 MPI 看看...

WinTabber

這幾天一直在趕程式,但是由於要跑的 benchmark 實在太大,比較大的 case 跑一次少說要兩三小時,一秒上下幾十萬次的我當然沒有那麼多美國時間把那些 benchmark 在同一台機器上面一一跑完,所以理所當然的開了一堆 putty 在跑。

不過問題來了,總共要跑的 benchmark 也有個 15 組,雖然我手上可以用的機器並沒有到 15 台,不過也是有個十台左右。開了十個 putty 的桌面實在是亂七八糟,搞不請楚哪個視窗是哪台機器。找了一下 putty 是有 PuttyTabs 這個 Tab 的支援,不過我想了一想,覺得應該會有讓所有程式都可以支援 Tab 的方法,所以找了一下發現了 WinTabber 這個好東西。

WinTabber 不僅僅可以支援 putty,也可以支援許多程式。使用的方法也很簡單,打開 WinTabber 之後選擇 File->New Tab,接著再選擇要加入 Tab 的程式。如此就可以讓程式也支援 Tab 了。

目前使用起來是沒啥問題,除了偶爾 focus 會跑掉之外都還蠻讓我滿意的。在 putty 本身真正的支援 Tab 之前我應該會繼續使用吧。

點廣告賺錢

紀錄一下點廣告賺錢的 link,隨時會更新...
CLix4coins
Just-Click
Bux.to
bux3.com
Hits4Pay
DailyClicks
Paid.vg
Fast.sc
10Bux.net

Boost Libraries: Foreach

BOOST_FOREACH 是甚麼?

在 C++ 中,寫一個 iterate 一整個 sequence 的迴圈是讓人厭煩的,我們可以用 iterators,但是需要寫很多照本宣科的程式碼。或是我們可以用 std::for_each() 演算法,但是其實它也沒有省下多少功夫。相對之下,像是 Perl 之類的語言提供了內建的 "foreach" 來自動建構這樣的程序。BOOST_FOREACH 就是這類程序的 C++ 版本。它會直接幫助我們 iterates 整個 seqeuce,讓我們不用跟 iterators 奮鬥。

BOOST_FOREACH 是為了簡單易用以及有效率而設計的,他不會做動態 allocation,沒有 virtual function calls 也不用任何的 function pointers。這讓它可以產生 near-optimal 的程式碼,BOOST_FOREACH 的效率通常只跟手寫的 loop 差了幾個百分比而已。儘管 BOOST_FOREACH 是一個 macro,他的表現相當的出色。它剛好 evaluate 他的 argument 一次,讓我們不會看到有預期之外的效果。

Hello, world!

下面是一個簡單的程式,它使用了 BOOST_FOREACH 來 iterate 一個 std::string 的內容。
#include <string>
#include <iostream>
#include <boost/foreach.hpp>

int main()
{
    std::string hello( "Hello, world!" );
    
    BOOST_FOREACH( char ch, hello )
    {
        std::cout << ch;
    }

    return 0;
}
程式會 output
Hello world!
支援的類型

BOOST_FOREACH 會 iterates seqeuces,不過甚麼才會真正的組成一個 sequence?BOOST_FOREACH 是建構在 Boost.Range 之上,所以它自然會支援那些 Boost.Range 可以辨認的類型。舉例來說,我們可以用:
    * STL containers
    * arrays
    * Null-terminated strings (char and wchar_t)
    * std::pair of iterators
範例

下面是幾個使用 BOOST_FOREACH 的範例: 在 STL container 做 iterate:
std::list list_int( /*...*/ );
BOOST_FOREACH( int i, list_int )
{
    // do something with i
}
在 array 上面做 iterate with covariance (就是說 iteration variable 跟 element 的型別不完全一致)
short array_short[] = {1,2,3};
BOOST_FOREACH( int i, array_short )
{
    // The short was implicitly converted to an int
}
在 loop 中使用 return, continue 以及 break
std::deque deque_int( /*...*/ );
int i = 0;
BOOST_FOREACH( i, deque_int )
{
    if( i == 0 ) return;
    if( i == 1 ) continue;
    if( i == 2 ) break;
}
透過 reference iterate 整個 sequence,並且做變更
short array_short[] = { 1, 2, 3 };
BOOST_FOREACH( short & i, array_short )
{
    ++i;
}
// array_short contains {2,3,4} here
利用巢狀 BOOST_FOREACH iterate 一個二維 vector
std::vector<std::vector<int> > matrix_int;
BOOST_FOREACH( std::vector<int> & row, matrix_int )
    BOOST_FOREACH( int & i, row )
        ++i;

google code prettify

這幾天一直在找在 blogger 上面可以讓貼程式碼比較方便的辦法,最後在 dp.SyntaxHighlighter 和 google-code-prettify 之間我選擇了 google code prettify。

google-code-prettify 的使用相當簡單,首先先去下載網頁上面抓下它的 CSS 和 js 檔案,上傳到網頁空間。接著在網頁前面加上:
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
其中,prettify.css 和 prettify.js 這兩個檔案必須更改正確的路徑。接著,在 body 這個 tag 加上 onload="prettyPrint()",這樣就完成了設定的動作。

當你要將某段 code 貼上時,你只要將要貼上的 code 以 <pre class="prettyprint">...</pre>包起來,就可以達到 syntax highlight 的效果。

Firefox 擴充套件整理

稍微整理一下自己平常會使用的 extension 0rz creater
http://0rz.tw/ 這個短網址的 creator,在 ptt 低調的時候很好用

Adblock
擋廣告必備!

All-in-One Gestures
透過滑鼠手勢,讓你瀏覽網頁可以更加直覺

Download statusbar
直接在 Statusbar 看到下載的情況

Forecastfox
你想知道明天天氣如何嗎?ForecastFox 是你的好朋友


IE View
遇到 IE only 的網頁時,就需要 IE View 幫你開啟網頁

Nightly Tester Tools
強迫讓 Extensions 相容於目前使用的 firefox

Right Encoding 直接按右鍵即可改變編碼


Show Image
遇到沒顯示出來的圖片時,可以直接按右鍵「顯示圖片」

Tab Mix Lite CE
有關 Tab 的一些小功能

新同文堂
簡體繁體互換方便的 extension

Google Adsense 支援繁體中文


trad, originally uploaded by Dkr.

剛剛發現 google adsense 出現繁體廣告了,不過我的 blog 跟高壓清潔器有啥關係?

Google Adsense


scotty, originally uploaded by Dkr.

因為我 po 了一篇 "Scotty doesn't know",所以 google adsense 就出現了這個廣告 XD

Firefox 2.0 is out!

雖然在 Mozilla 的網頁上還只是 Download Firefox 1.5,不過其實 Firefox 2.0 正式版已經出了,只是沒有公告而已。Firefox 2.0 可以在這裡抓到。趕在現在推出有跟 IE7 互相對幹的意味 XD
 

Popular Posts