Say that I have some user-defined complex struct, like
struct usrStruct{
double a;
T1 b;
T2 c;
/* and so on...*/
}
which is used as a basic element for a std::vector, std::list or anything iterable..
Say that the std::vector<usrStruct> is passed to a function of mine through iterators
template<class InputIterator>
T myFoo( InputIterator first, InputIterator last ){ /*...*/ }.
Q: Is there a standard way to override operator*() of the InputIterator, (in this case of std::vector<usrStruct>::iterator ) so that myFoo just interacts with the member a?
i.e., so that
*first == (*first).a;
and thus myFoo works orthogonally with respect to the whole definition of usrStruct?
Thank you.
No, you cannot do that. You can make your struct implicitly convertible to a double (via
operator double). Or you can allow direct comparisons by overloadingoperator==(usrSruct,double)and/oroperator==(double,usrStruct).