Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active April 9, 2017 12:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save deque-blog/c1ce60d2a4a2c7a4ce96a1038dad0316 to your computer and use it in GitHub Desktop.
template <
typename LhsForwardIterator,
typename RhsForwardIterator,
typename Less = std::less<typename LhsForwardIterator::value_type>
>
bool is_permutation_less(
LhsForwardIterator lhs_first, LhsForwardIterator lhs_last,
RhsForwardIterator rhs_first, RhsForwardIterator rhs_last,
Less less = Less())
{
using value_type = typename LhsForwardIterator::value_type;
std::vector<value_type> lhs(lhs_first, lhs_last);
std::vector<value_type> rhs(rhs_first, rhs_last);
if (lhs.size() != rhs.size())
return false;
std::sort(begin(lhs), end(lhs));
std::sort(begin(rhs), end(rhs));
return lhs == rhs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment