#include <iostream>
using namespace std;
struct Pair{
int a;
int b;
};
ostream& operator<<(ostream& os, const Pair& p) {
return os<<"("<<p.a<<", "<<p.b<<")";
}
void find_ptr_member(Pair array[], int size, int Pair::*where, int what){
for(int i=0;i<size;++i){
if(array[i].*where==what){
cout<<"Found with pointer to member "<<array[i]<<endl;
}
}
}
void find_ptr_func(Pair array[], int size, bool (*isIt)(Pair&)){
for(int i=0;i<size;++i){
if(isIt(array[i])){
cout<<"Found with pointer to function "<<array[i]<<endl;
}
}
}
#define FIND_MACRO(array, size, member, value) { \
for(int i=0;i<size;++i){ \
if(array[i].member==value){ \
cout<<"Found with macro "<<array[i]<<endl; \
} \
} \
}
int main() {
Pair p[10];
for(int i=0;i<10;++i){
p[i].a=i;
p[i].b=10-i;
}
find_ptr_member(p,10,&Pair::b,3);
find_ptr_func(p,10,[](Pair&p){return p.b==6;});
FIND_MACRO(p,10,b,2);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBQYWlyewoJaW50IGE7CglpbnQgYjsKfTsKCm9zdHJlYW0mIG9wZXJhdG9yPDwob3N0cmVhbSYgb3MsIGNvbnN0IFBhaXImIHApIHsKCXJldHVybiBvczw8IigiPDxwLmE8PCIsICI8PHAuYjw8IikiOwp9Cgp2b2lkIGZpbmRfcHRyX21lbWJlcihQYWlyIGFycmF5W10sIGludCBzaXplLCBpbnQgUGFpcjo6KndoZXJlLCBpbnQgd2hhdCl7Cglmb3IoaW50IGk9MDtpPHNpemU7KytpKXsKCQlpZihhcnJheVtpXS4qd2hlcmU9PXdoYXQpewoJCQljb3V0PDwiRm91bmQgd2l0aCBwb2ludGVyIHRvIG1lbWJlciAiPDxhcnJheVtpXTw8ZW5kbDsKCQl9Cgl9Cn0KCnZvaWQgZmluZF9wdHJfZnVuYyhQYWlyIGFycmF5W10sIGludCBzaXplLCBib29sICgqaXNJdCkoUGFpciYpKXsKCWZvcihpbnQgaT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