I need a container in which I can check if a sequence of elements are present or not. Same thing as substring matching, just for generic collections. I know it's not hard to write, but if it's implemented in some lib already, I wouldn't bother (maybe Boost has something like this?)
+8
A:
Any sequence container will do. You just need to use std::search algorithm to do the search of the sublist:
vector<int> sequence = ...;
vecter<int> sublist = ...;
vector<int>::iterator pos = std::search(
sequence.begin(), sequence.end(),
sublist.begin(), sublist.end());
if(pos == sequence.end())
// not fount
else
// found at pos
ybungalobill
2010-10-09 16:33:53
oh god how did I miss this one :). Thanks.
Tamás Szelei
2010-10-09 16:38:56
@Tamás: If you think this is the answer to your question, please vote it up ans ACCEPT it by clicking the v-like thing under the answer vote count. Thank you
Armen Tsirunyan
2010-10-09 16:48:55
@Armen, yeah, it just wouldn't let me to accept it that fast, so I had to wait.
Tamás Szelei
2010-10-09 17:13:14
A:
The mismatch algorithm from STL is pretty much strcmp for generic containers.
Let_Me_Be
2010-10-09 16:35:00