I'm in need of the opposite of is_permutation. So I looked at the c++ reference and saw this in regards to is_permutation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
template <class InputIterator1, class InputIterator2>
bool is_permutation (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2)
{
std::tie (first1,first2) = std::mismatch (first1,last1,first2);
if (first1==last1) returntrue;
InputIterator2 last2 = first2; std::advance (last2,std::distance(first1,last1));
for (InputIterator1 it1=first1; it1!=last1; ++it1) {
if (std::find(first1,it1,*it1)==it1) {
auto n = std::count (first2,last2,*it1);
if (n==0 || std::count (it1,last1,*it1)!=n) returnfalse;
}
}
returntrue;
}
In one of my earlier topics, keskiverto created a custom template for me that worked perfectly!! So, I thought that maybe if I made some changes, I could create isnot_permutation. I was very aprehensive to try this without knowing what I was doing. I thought that maybe if I change the name and the return bools that maybe it would work. First I just changed the last return bool and it didn't workout. Then I changed all the bool values and it seemed to work ok. Not enough testing done yet. But can more expoerienced people check this idea out. I have absolutely no knowledge on doing something like this. Am I on the verge of creating potentially more problems? I just thought I would give it a try. Like I said, I haven't done much testing yet, but checkout the template that I modified. Is it ok?? Heck, I don't even understand what some of it means YET. Here is what I did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
template <class InputIterator1, class InputIterator2>
bool isnot_permutation (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2)
{
std::tie (first1,first2) = std::mismatch (first1,last1,first2);
if (first1==last1) returnfalse;
InputIterator2 last2 = first2; std::advance (last2,std::distance(first1,last1));
for (InputIterator1 it1=first1; it1!=last1; ++it1) {
if (std::find(first1,it1,*it1)==it1) {
auto n = std::count (first2,last2,*it1);
if (n==0 || std::count (it1,last1,*it1)!=n) returntrue;
}
}
returnfalse;
}