I wrote a generic function for finding out if one container sequence can be found inside another:
Problem is, when it does reach the conditional inside the loop, and goes inside it, it "returns false", exits the loop, then "returns true". I followed it inside a debugger, and that's exactly what it did before my own eyes.Code:template <class Container> bool is_in(const Container& c1, const Container& c2) { typename Container::const_iterator it, prev_find, this_find; it = c1.begin(); prev_find = find(c2.begin(), c2.end(), *it++); for(; it != c1.end(); it++) { this_find = find(++prev_find, c2.end(), *it); if(prev_find != this_find || this_find == c2.end()) { return false; } } return true; }
I always that if a program hits a "return" directive, it's supposed to exit the function no matter what. What am I doing wrong here?



LinkBack URL
About LinkBacks



