Or login with:
#include <algorithm> template < class InputIterator1, class InputIterator2 > bool includes( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last1 ); template < class InputIterator1, class InputIterator2, class BinaryPredicate > bool includes( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last1, BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| first1 | An input iterator addressing the position of the first element in the first of two sorted source ranges to be tested for whether all the elements of the second are contained in the first |
| last1 | An input iterator addressing the position one past the last element in the first of two sorted source ranges to be tested for whether all the elements of the second are contained in the first |
| first2 | An input iterator addressing the position of the first element in second of two consecutive sorted source ranges to be tested for whether all the elements of the second are contained in the first |
| last2 | An input iterator addressing the position one past the last element in second of two consecutive sorted source ranges to be tested for whether all the elements of the second are contained in the first |
| comp | User-defined predicate function object that defines sense in which one element is less than another. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
[first2, last2)) contains all the elements contained in a second sorted range ([first1, last1)), where the ordering or equivalence criterion between elements may be specified by a binary predicate.
The first version compares objects using operator<, and the second compares objects using a function object comp.[first2, last2) is a member of [first1, last1), otherwise returns false.2 * ((last1 - first1) + (last2 - first2)) - 1 comparisons.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a1[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; vector<int> v1(a1, a1+10); cout <<"\nHere are the contents of v1:\n"; for (vector<int>::size_type i=0; i<v1.size(); i++) cout <<v1.at(i)<<" "; int a2[] = {2, 16, 128, 512}; vector<int> v2(a2, a2+4); cout <<"\nHere are the contents of v2:\n"; for (vector<int>::size_type i=0; i<v2.size(); i++) cout <<v2.at(i)<<" "; if (includes(v1.begin(), v1.end(), v2.begin(), v2.end())) cout <<"\nv1 includes v2."; else cout <<"\nv1 does not include v2."; int a3[] = {2, 16, 128, 1024}; vector<int> v3(a3, a3+4); cout <<"\nHere are the contents of v3:\n"; for (vector<int>::size_type i=0; i<v3.size(); i++) cout <<v3.at(i)<<" "; if (includes(v1.begin(), v1.end(), v3.begin(), v3.end())) cout <<"\nv1 includes v3."; else cout <<"\nv1 does not include v3."; return 0; }
You must login to leave a messge