includes function template — Tests sorted ranges for subset
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)
.
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.