[ create a new paste ] login | about

Link: http://codepad.org/QWQJCLNN    [ raw code | output | fork ]

fenrir - C++, pasted on Apr 3:
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

struct A {
  int v;
  int f1(const int &_v){
    return v * _v;
  }
  int f2(const int &_v){
    return v * _v * _v;
  }
};

int main(){
  A a[3];
  for(unsigned int i(0); i < sizeof(a) / sizeof(a[0]); i++){
    a[i].v = i + 1;
  }
  
  typedef vector<pair<A *, int (A::*)(const int &)> > vec_t;
  vec_t vec;
  for(unsigned int i(0); i < sizeof(a) / sizeof(a[0]); i++){
    for(int j(0); j < 2; j++){
      vec.push_back(vec_t::value_type(&a[i], j % 2 == 0 ? &A::f1 : &A::f2));
    }
  }

  for(vec_t::const_iterator it(vec.begin()); it != vec.end(); ++it){
    cout << ((it->first)->*(it->second))(2) << endl;
  }
  
  return 0;
}


Output:
1
2
3
4
5
6
2
4
4
8
6
12


Create a new paste based on this one


Comments: