Created
January 7, 2014 22:03
-
-
Save dgodfrey206/8307750 to your computer and use it in GitHub Desktop.
Subset function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
template< class ForwardIt1, class ForwardIt2 > | |
bool is_subset(ForwardIt1 first1, ForwardIt1 last1, | |
ForwardIt2 first2, ForwardIt2 last2) | |
{ | |
auto initial = first2; | |
for (; (first1 != last1) && (first2 != last2); ++first1) | |
{ | |
if (*first1 != *first2) | |
first2 = initial; | |
else | |
++first2; | |
} | |
return first2 == last2; | |
} | |
int main() | |
{ | |
std::string x("abcheloxyz"), y("z"); | |
std::cout << std::boolalpha; | |
std::cout << is_subset(x.begin(), x.end(), | |
y.begin(), y.end()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment