I want to write a C++ generic algorithm that can work on set, list, map, vector, etc... So this algorithm accepts a container and a function object, so I can check for certain conditions.
This algorithm needs to check the longest series in the container according to a certain condition and return its length.
i am having trouble in passing the function object to the function as i get this error (in the second line in main) :
"Multiple markers at this line - Invalid arguments ' Candidates are: void functionA(#0 &, #0 &, #1) ' - invalid initialization of non-const reference of type 'int*&' from an rvalue of type 'std::array::iterator {aka "
i don't understand the problem since there is an operator () , in the function object :\ even if i call the constructor first i still get this error ..
what i tried :
template<typename T,typename Predicate>
void functionA(T& it1 , T& end1,Predicate pred){
for(;it1 != end1; ++it1){
T it2=it1++;
if(!pred(*it1,*it2)){
std::cout << *it1 << "\n" ;
return;
}
}
std::cout <<"not found" << "\n" ;
}
class FindFirst {
public:
FindFirst();
bool operator()(int f , int s) const {
return f < s;
}
};
int main() {
std::array<int,11> myarray = {1,2,4,7,10,14,3,6,12,24,48};
functionA(myarray.begin(),myarray.end(),find);
}