Name
includes function template — Tests sorted ranges for subset
Synopsis
template<typename InIter1, typename InIter2> bool includes(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2); template<typename InIter1, typename InIter2, typename Compare> bool includes(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, Compare comp);
The includes
function
template checks for a subset relationship, that is, it returns
true
if every element in the
sorted sequence [first2
, last2
) is contained in the sorted sequence
[first1
, last1
). It returns false
otherwise.
Both sequences must be sorted. The first form uses the
<
operator to compare the
elements. The second form calls comp(*iter1
, *iter2)
.
Technical Notes
Precondition: !(*(i + 1) < *i) for all i in [first1, last1 - 1) and !(*(j + 1) < *j) for all j in [first2, last2 - 1).
The includes
function
template returns true
if there is
an i in [first1, last1) such that *(i + n) = *(first2
+ n) for all
n in [0, (last2 - first2)). It returns last1 if there is no such i.
Complexity is linear: at most, 2 × ((last1 - first1) + (last2 - first2)) - 1 comparisons are performed.
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.