fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Pair{
  6. int a;
  7. int b;
  8. };
  9.  
  10. ostream& operator<<(ostream& os, const Pair& p) {
  11. return os<<"("<<p.a<<", "<<p.b<<")";
  12. }
  13.  
  14. void find_ptr_member(Pair array[], int size, int Pair::*where, int what){
  15. for(int i=0;i<size;++i){
  16. if(array[i].*where==what){
  17. cout<<"Found with pointer to member "<<array[i]<<endl;
  18. }
  19. }
  20. }
  21.  
  22. void find_ptr_func(Pair array[], int size, bool (*isIt)(Pair&)){
  23. for(int i=0;i<size;++i){
  24. if(isIt(array[i])){
  25. cout<<"Found with pointer to function "<<array[i]<<endl;
  26. }
  27. }
  28. }
  29.  
  30. #define FIND_MACRO(array, size, member, value) { \
  31. for(int i=0;i<size;++i){ \
  32. if(array[i].member==value){ \
  33. cout<<"Found with macro "<<array[i]<<endl; \
  34. } \
  35. } \
  36. }
  37.  
  38. int main() {
  39. Pair p[10];
  40. for(int i=0;i<10;++i){
  41. p[i].a=i;
  42. p[i].b=10-i;
  43. }
  44. find_ptr_member(p,10,&Pair::b,3);
  45. find_ptr_func(p,10,[](Pair&p){return p.b==6;});
  46. FIND_MACRO(p,10,b,2);
  47. return 0;
  48. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Found with pointer to member (7, 3)
Found with pointer to function (4, 6)
Found with macro (8, 2)