STL 介面卡實現

2021-04-02 09:20:50 字數 4309 閱讀 2008

//函式介面轉函式物件介面的介面卡(內部呼叫引數為指標型別)

template

class const_mem_fun_t : public unary_function

_ret operator()(const _tp* __p) const

private:

_ret (_tp::*_m_f)() const;

};//const函式介面轉函式物件介面的介面卡(內部呼叫引數為const指標型別)

template

class mem_fun_ref_t : public unary_function<_tp,_ret>

_ret operator()(_tp& __r) const

private:

_ret (_tp::*_m_f)();

};//內部呼叫引數為引用型別

template

class const_mem_fun_ref_t : public unary_function<_tp,_ret>

_ret operator()(const _tp& __r) const

private:

_ret (_tp::*_m_f)() const;

};//內部呼叫引數為const引用型別

template

class mem_fun1_t : public binary_function<_tp*,_arg,_ret>

_ret operator()(_tp* __p, _arg __x) const

private:

_ret (_tp::*_m_f)(_arg);

};template

class const_mem_fun1_t : public binary_function

_ret operator()(const _tp* __p, _arg __x) const

private:

_ret (_tp::*_m_f)(_arg) const;

};//接受乙個引數的介面卡

template

class mem_fun1_ref_t : public binary_function<_tp,_arg,_ret>

_ret operator()(_tp& __r, _arg __x) const

private:

_ret (_tp::*_m_f)(_arg);

};template

class const_mem_fun1_ref_t : public binary_function<_tp,_arg,_ret>

_ret operator()(const _tp& __r, _arg __x) const

private:

_ret (_tp::*_m_f)(_arg) const;

};template

class mem_fun_t: public unary_function<_tp*,void>

void operator()(_tp* __p) const

private:

void (_tp::*_m_f)();

};template

class const_mem_fun_t: public unary_function

void operator()(const _tp* __p) const

private:

void (_tp::*_m_f)() const;

};template

class mem_fun_ref_t: public unary_function<_tp,void>

void operator()(_tp& __r) const

private:

void (_tp::*_m_f)();

};template

class const_mem_fun_ref_t: public unary_function<_tp,void>

void operator()(const _tp& __r) const

private:

void (_tp::*_m_f)() const;

};template

class mem_fun1_t: public binary_function<_tp*,_arg,void>

void operator()(_tp* __p, _arg __x) const

private:

void (_tp::*_m_f)(_arg);

};template

class const_mem_fun1_t

: public binary_function

void operator()(const _tp* __p, _arg __x) const

private:

void (_tp::*_m_f)(_arg) const;

};template

class mem_fun1_ref_t

: public binary_function<_tp,_arg,void>

void operator()(_tp& __r, _arg __x) const

private:

void (_tp::*_m_f)(_arg);

};template

class const_mem_fun1_ref_t

: public binary_function<_tp,_arg,void>

void operator()(const _tp& __r, _arg __x) const

private:

void (_tp::*_m_f)(_arg) const;

};// mem_fun adaptor helper functions.  there are only two:

//  mem_fun and mem_fun_ref.  (mem_fun1 and mem_fun1_ref

//  are provided for backward compatibility, but they are no longer

//  part of the c++ standard.)

template

inline mem_fun_t<_ret,_tp> mem_fun(_ret (_tp::*__f)())

template

inline const_mem_fun_t<_ret,_tp> mem_fun(_ret (_tp::*__f)() const)

template

inline mem_fun_ref_t<_ret,_tp> mem_fun_ref(_ret (_tp::*__f)())

template

inline const_mem_fun_ref_t<_ret,_tp> mem_fun_ref(_ret (_tp::*__f)() const)

template

inline mem_fun1_t<_ret,_tp,_arg> mem_fun(_ret (_tp::*__f)(_arg))

template

inline const_mem_fun1_t<_ret,_tp,_arg> mem_fun(_ret (_tp::*__f)(_arg) const)

template

inline mem_fun1_ref_t<_ret,_tp,_arg> mem_fun_ref(_ret (_tp::*__f)(_arg))

template

inline const_mem_fun1_ref_t<_ret,_tp,_arg>

mem_fun_ref(_ret (_tp::*__f)(_arg) const)

template

inline mem_fun1_t<_ret,_tp,_arg> mem_fun1(_ret (_tp::*__f)(_arg))

template

inline const_mem_fun1_t<_ret,_tp,_arg> mem_fun1(_ret (_tp::*__f)(_arg) const)

template

inline mem_fun1_ref_t<_ret,_tp,_arg> mem_fun1_ref(_ret (_tp::*__f)(_arg))

template

inline const_mem_fun1_ref_t<_ret,_tp,_arg>

mem_fun1_ref(_ret (_tp::*__f)(_arg) const)

//對上面各個函式物件的簡化包裝

STL介面卡 函式介面卡

有時候需要對內建函式物件返回值進行進一步的簡單計算,或者填上多餘的引數,不能直接代入演算法。函式介面卡實現了這一功能,函式介面卡是將一種函式物件轉化為另一種符合要求的函式物件。函式介面卡可以分為4個大類 繫結介面卡 組合介面卡 指標函式介面卡和成員函式介面卡。需求 在遍歷容器的時候,將容器中的值全部...

STL 容器介面卡

那麼c 中的容器介面卡是幹什麼的呢?可以做乙個模擬,我們已有的容器 比如vector list deque 就是裝置,這個裝置支援的操作很多,比如插入,刪除,迭代器訪問等等。而我們希望這個容器表現出來的是棧的樣子 先進後出,入棧出棧等等,此時,我們沒有必要重新動手寫乙個新的資料結構,而是把原來的容器...

STL容器介面卡

stl學習系列之六 容器介面卡 stl提供了三種容器介面卡 stack,queue,priority queue。介面卡並不是第一類容器,因為它們並沒有提供與元素的儲存形式有關的真正資料結構實現,並且介面卡不支援迭代器。介面卡的優點是 能夠使程式設計師選擇一種合適的底層資料結構。這三個介面卡類都提供...