0

Is there a way to return a distance between the first iterator of a sequence, which yields the start of a subsequence in case it is contained within the sequence?

I know there is std::includes which returns true if a sequence is a subsequence of another. And it can take a Compare object. My first guess was to have an object to increment a captured iterator (inside a lambda) every time the start of a subsequence is found. But then I realized that both sequences must be sorted, and a Compare object must return true on a < b.

Can this be done using the std algorithms library?

Sergey Kolesnik
  • 3,009
  • 1
  • 8
  • 28
  • Just checking: your sequences are sorted? – Marc Glisse Dec 06 '20 at 17:10
  • @MarcGlisse no. I am searching for the iterator of the received byte array, where the message header starts. – Sergey Kolesnik Dec 06 '20 at 17:12
  • What does "the first iterator of a sequence, which yields the start of a subsequence in case it is contained within the sequence" mean? It would help if you provide a clear, concise example of what you're looking for. – Sam Varshavchik Dec 06 '20 at 17:15
  • @SamVarshavchik Jarod42 has answered. I meant that I need to find an iterator of a sequence, where the subsequence begins if it is contained within. `std::search` seems to be what I am looking for. – Sergey Kolesnik Dec 06 '20 at 17:17

1 Answers1

3

It seems you are looking for std::search.

Jarod42
  • 203,559
  • 14
  • 181
  • 302