#include <iostream>
#include <list>
#include <functional>
#include <algorithm>

using namespace std;


class fuctor{

public :
 int m_MemData;
 static int m_data;

public :
 fuctor(int ini) {
  m_MemData = ini;
 }
 fuctor() {
  m_MemData = m_data++;
 }
 int operator+( int data ) const{
  return this->m_MemData + data;
 }
 void show(int data){
  cout<<m_MemData + data<<"\t";
 }


};

int fuctor::m_data = 1;


class IntSequence{

public :
 fuctor operator()(){
  return fuctor();
 }

};

template<typename T1,typename T2>
class plus1 : public binary_function<T1,T2,T1>{
public :
 T1 operator()(const T1 lhs,const T2 rhs) const {
  return  T1(lhs + rhs);
 }
};

 

int main(){

 list<fuctor> coll2;
 
 generate_n( back_inserter(coll2),10,  IntSequence() );

 transform(coll2.begin(),coll2.end(),coll2.begin(), bind2nd( plus1<fuctor,int>(),10 ) );

 for_each( coll2.begin(),coll2.end(), bind2nd(mem_fun_ref(&fuctor::show) ,100)  );
 
 if(getchar())
  return 0;
}

반응형

+ Recent posts