#include <iostream>
#include <vector>
#include <string>
#include <limits>
using namespace std;
struct Object {
std::string name;
int a;
int b;
int c;
};
class ObjectCollection {
size_t getMaxIndexOf(int Object::* o); // private helper function
public:
std::vector<Object> collection;
size_t getMaxIndexOfA();
size_t getMaxIndexOfB();
size_t getMaxIndexOfC();
};
size_t ObjectCollection::getMaxIndexOf(int Object::* o) {
size_t maxIndex = -1;
int max = std::numeric_limits<int>::min();
for (size_t i = 0; i < collection.size(); ++i) {
if (collection[i].*o > max) {
maxIndex = i;
max = collection[i].*o;
}
}
return maxIndex;
}
size_t ObjectCollection::getMaxIndexOfA() {
return getMaxIndexOf(&Object::a);
}
size_t ObjectCollection::getMaxIndexOfB() {
return getMaxIndexOf(&Object::b);
}
size_t ObjectCollection::getMaxIndexOfC() {
return getMaxIndexOf(&Object::c);
}
int main() {
ObjectCollection c;
c.collection.push_back({"test0" , 1,2,3 });
c.collection.push_back({"test1" , 2,1,4 });
c.collection.push_back({"test2" , 3,1,2 });
cout << c.getMaxIndexOfA() <<" " << c.getMaxIndexOfB() <<" " << c.getMaxIndexOfC() <<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bGltaXRzPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IE9iamVjdCB7CiAgICBzdGQ6OnN0cmluZyBuYW1lOwogICAgaW50IGE7CiAgICBpbnQgYjsKICAgIGludCBjOwp9OwoKY2xhc3MgT2JqZWN0Q29sbGVjdGlvbiB7CiAgICBzaXplX3QgZ2V0TWF4SW5kZXhPZihpbnQgT2JqZWN0OjoqIG8pOyAvLyBwcml2YXRlIGhlbHBlciBmdW5jdGlvbiAKcHVibGljOgogICAgc3RkOjp2ZWN0b3I8T2JqZWN0PiBjb2xsZWN0aW9uOwogICAgc2l6ZV90IGdldE1heEluZGV4T2ZBKCk7CiAgICBzaXplX3QgZ2V0TWF4S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