-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincludes_unordered.hpp
59 lines (55 loc) · 1.35 KB
/
includes_unordered.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef INCLUDES_UNORDERED_HPP
#define INCLUDES_UNORDERED_HPP
#include <iterator>
/*!
* Returns true if every element from the unsorted range [first2, last2)
* is found within the unsorted range [first1, last1).
* Also returns true if [first2, last2) is empty.
*/
template <typename InputIt1, typename InputIt2>
bool includes_unordered(
InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
InputIt2 last2)
{
for(; first2 != last2; ++first2)
{
InputIt1 it1;
for(it1 = first1; it1 != last1; ++it1)
{
if(*first2 == *it1)
break;
}
if(it1 == last1)
return false;
}
return true;
}
/*!
* Returns true if every element from the unsorted range [first2, last2)
* is found within the unsorted range [first1, last1).
* Also returns true if [first2, last2) is empty.
*/
template <class InputIt1, typename InputIt2, typename Equivalence>
bool includes_unordered(
InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
InputIt2 last2,
Equivalence equiv)
{
for(; first2 != last2; ++first2)
{
InputIt1 it1;
for(it1 = first1; it1 != last1; ++it1)
{
if(equiv(*first2, *it1))
break;
}
if(it1 == last1)
return false;
}
return true;
}
#endif // INCLUDES_UNORDERED_HPP