在C++98/03時期,有這麼一條規則Every C++ expression is either an lvalue or an rvalue.,Lvalue是在運算過後留下來的續存物件,而Rvalue是運算過後生命期就結束的臨時物件。 殂此之外,C++98/03裡還有一條規則A function call is an lvalue if and only if the result type is a reference
structAdd2 { intoperator()(int a, int b) { return a + b; } }; intsub2(int a, int b){ return a - b; } template <typename T> intoperate(int a, int b, T callback) { return callback(a, b); } operate(3, 2, Add2()); operate(3, 2, sub2);
之後有人想要將class member method跟static class method也包裝成Functor的形式,有Loki跟Boost兩大主流為主。這裡就不多談了,在C++0x中也將boost的bind跟function列入TR1裡,可以很方便的產生Functor。
std::forward_list is a container that supports fast insertion and removal of elements from anywhere in the container. Fast random access is not supported. It is implemented as singly-linked list and essentially does not have any overhead compared to its implementation in C. Compared to std::list this container provides more space efficient storage when bidirectional iteration is not needed.
$ gcc main.c libTest.a -o main libTest.a: could not read symbols: Archive has no index; run ranlib to add one collect2: ld returned 1 exit status
用nm看一下libTest.a
1 2 3 4 5
$ nm -s libTest.a
foo.o: 0000000000000000 T foo
nm對-s的說明如下
When listing symbols from archive members, include the index: a mapping (stored in the archive by ar or ranlib) of which modulescontain definitions for which names.