Skip to content

Instantly share code, notes, and snippets.

@tenor
Forked from dgodfrey206/gist:8307750
Created January 7, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenor/8307940 to your computer and use it in GitHub Desktop.
Save tenor/8307940 to your computer and use it in GitHub Desktop.
#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