函式配接器

2022-09-20 01:54:12 字數 868 閱讀 8551

函式配接器

bind1st(op,value) ----> op(value,param)     //繫結op的第乙個引數

bind2st(op,value) ----> op(param,value)

not1(op) ---->!op(param)

not2(op) ---->!op(param1,param2)

int func1(int p1,int

p2 )

int main(int argc, char*ar**)

這是乙個使用示例,看到其中有個ptr_fun,這是幹嘛的呢?

ptr_fun即是針對一般函式設計的函式配接器;

另有mem_fun_ref(op)   :針對某物件的乙個const成員函式

mem_fun(op)  :針對某函式指標的乙個const成員函式

//在vs2012上編譯通過,vc6.0編譯失敗

#include "

stdafx.h

"#include

#include

#include

#include

using

namespace

std;

int func1(int p1,int

p2 )

class

myclass

int func2(int

i)};

int main(int argc, char*ar**)

注意點: 在帶乙個引數的成員函式繫結時用的是bind2nd,查過資料後知道了原因:第乙個引數就相當於this指標了,繫結第二個引數就是繫結成員函式第乙個引數

c 函式配接器

所謂的 函式配接器 是指可以把仿函式和另乙個仿函式 或某個值,或某個一般函式 結合起來的仿函式。函式配接器也定義在標頭檔案 functional 中。include例如 finf if coll.begin coll.end range bind2nd reater,40 criterion其中的表...

四種函式配接器

bind1nd op value 相當於構成op value,param2 即用value覆蓋掉op的第乙個引數 bind2nd op value 相當於構成op param1,value 即用value覆蓋掉op的第二個引數2 對於接受乙個引數的仿函式op param not1 op 相當於構成 ...

容器配接器 stacks

stack 堆疊 的簡單使用 include include using namespace std int main if st st1 cout st.size endl 棧中元素的個數 cout st.top endl 返回棧頂元素 st.pop 出棧 st.top 12 改變棧頂元素值 st...