List search algorithm

I am trying to translate using the find function in Matlab to C ++ . From what I can see from the C ++ search function, I cannot find in the description anywhere a simple method of finding an index in a list in which certain conditions are true, not just a comparison for equality between the element that is the search and the list of elements. Before I start using my own method for executing the find function, it would be great to see if there is any simple, efficient, standard implemented way to do this already. Thanks in advance.

0


a source to share


2 answers


If you're looking for a math condition, you want "find_if". Using find if will allow you to pass in a predicate that determines if a given item in the list matches. You still have to write the matching logic (or find the corresponding existing function in the standard algorithms, but there is less of it than writing the whole "find" structure.



+2


a source


Again, the "whole search structure" is not that hard, even if you don't have tail recursion.



This might be an example of something worth writing yourself, because even if at the moment you are not as quick to hack the correct function as you would pick it from the standard library, after writing it a few more times you will. Not to mention, you really get to know what's going on under the hood as we speak in Chevy land.

0


a source







All Articles